@W-22699714: [Android] Improve error handling at code exchange#2932
Conversation
Add user-friendly 'app blocked' toast when code exchange fails with client_blocked error. Follows same pattern as existing Lightning URL error handling in LoginActivity.onAuthFlowError(). - Add sf__app_blocked_error string resource - Add isClientBlocked check + when expression for toast message - Add 3 doCodeExchange error path tests in LoginViewModelMockTest - Add 3 onAuthFlowError integration tests in LoginActivityAuthErrorTest
Generated by 🚫 Danger |
TokenErrorResponse.error and .errorDescription are public Java fields,
not methods. MockK's every { } block only intercepts method calls, so
using every { mock.error } returns value triggers "Missing mocked calls
inside every { ... } block". Fix by directly assigning the fields on
the relaxed mock instance instead.
| <string name="sf__managed_app_error">Authentication only allowed from managed device.</string> | ||
| <string name="sf__jwt_authentication_error">JWT authentication error. Please try again.</string> | ||
| <string name="sf__lightning_url_code_exchange_error">Lightning URLs are not supported for OAuth code exchange. Use your My Domain URL instead.</string> | ||
| <string name="sf__app_blocked_error">This app has been blocked. Contact your administrator for assistance.</string> |
There was a problem hiding this comment.
The server returns user_blocked error when the app failed app attestation.
The error returned will probably change (soon) to reflect that - but our message here could already be more descriptive.
| ) | ||
|
|
||
| viewModel.clearCookies() | ||
| val isClientBlocked = e is OAuthFailedException |
There was a problem hiding this comment.
Let's also recognize CLIENT_BLOCKED_RETRY_ERROR.
For now we will just bubble it up to the app/user.
Later, we might add retry-logic (in the case of refresh flow).
|
(For a new story / PR) should we revisit our oauth error parsing to include all server errors (see server enum here) ?? Ideally the user should never just see the almost white web page with a cryptic error string. @brandon-page @bbirman thoughts? |
yes please! |
Summary
client_blockederrorisLightningTokenEndpointFailurepattern inLoginActivity.onAuthFlowError()sf__app_blocked_errorstring resourceLoginViewModelMockTestLoginActivityAuthErrorTestTest plan
LoginViewModelMockTest.doCodeExchange_whenExchangeCodeThrowsClientBlocked_callsOnAuthFlowErrorpassesLoginViewModelMockTest.doCodeExchange_whenExchangeCodeThrowsIOException_callsOnAuthFlowErrorpassesLoginViewModelMockTest.doCodeExchange_whenExchangeCodeThrowsOAuthFailed_neverCallsOnAuthFlowCompletepassesLoginActivityAuthErrorTest.onAuthFlowError_givenClientBlocked_broadcastsWithCorrectExtraspassesLoginActivityAuthErrorTest.onAuthFlowError_givenClientBlocked_showsAppBlockedToastpassesLoginActivityAuthErrorTest.onAuthFlowError_givenGenericOAuthError_broadcastsWithCorrectExtraspasses