aws-amplify/amplify-swift

Discrepancy in error handling between iOS and Android for Amplify Auth

BigVeila opened this issue · 5 comments

Is your feature request related to a problem? Please describe.

I’ve noticed a significant discrepancy in how errors are handled and reported between iOS and Android for Amplify Auth. On iOS, errors are very simplified, using an enum like AuthError.invalidState with a general message. However, on Android, the same error provides much more detailed information, including the exception name like SignInException and additional context.

This inconsistency makes it challenging to maintain parity between platforms and handle errors effectively across both. For example, when trying to sign in while a user is already signed in:
• On iOS, the error is simply invalidState with a generic message. (About case Sign In Already, return only RecoverySuggestionn and ErrorDescription, Error is nil)
• On Android, the error includes the exception name SignInException, making it clearer and easier to debug.

Are there plans to align error reporting between iOS and Android so developers can have a consistent experience across platforms? It would be helpful if iOS errors could also include more detailed information, similar to Android.

Describe the solution you'd like

I would like to receive more detailed errors similar to those on Android.

Describe alternatives you've considered

No idea

Is the feature request related to any of the existing Amplify categories?

Auth

Additional context

No response

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

Hi @BigVeila, thanks for bringing this up. Currently there are no explicit plans for bringing the error handling into parity but we'll log this feature request in our backlog.

@BigVeila
Is this an issue with only About case Sign In Already?
Does Android also throw an invalid state and the underlying exception is SignInException?

@harsh62

Is this an issue with only About case Sign In Already?

  • No, I see that the Android side has many exceptions, but all of them are derived from 8 basic exceptions, which are also present on iOS

Does Android also throw an invalid state and the underlying exception is SignInException?

  • Yes

On iOS only have enum AuthError

`public enum AuthError {

/// Caused by issue in the way auth category is configured
case configuration(ErrorDescription, RecoverySuggestion, Error? = nil)

/// Caused by some error in the underlying service. Check the associated error for more details.
case service(ErrorDescription, RecoverySuggestion, Error? = nil)

/// Caused by an unknown reason
case unknown(ErrorDescription, Error? = nil)

/// Caused when one of the input field is invalid
case validation(Field, ErrorDescription, RecoverySuggestion, Error? = nil)

/// Caused when the current session is not authorized to perform an operation
case notAuthorized(ErrorDescription, RecoverySuggestion, Error? = nil)

/// Caused when an operation is not valid with the current state of Auth category
case invalidState(ErrorDescription, RecoverySuggestion, Error? = nil)

/// Caused when an operation needs the user to be in signedIn state
case signedOut(ErrorDescription, RecoverySuggestion, Error? = nil)

/// Caused when a session is expired and needs the user to be re-authenticated
case sessionExpired(ErrorDescription, RecoverySuggestion, Error? = nil)

}`

Hi @BigVeila,

Inconsistent error handling is something we would like to work on for a future Amplify major version. It is something that we can't easily reconcile on our v2, as it would require breaking changes, but we have held internal meetings on the topic. The current behavioral differences are partially due to language differences (ex: inheritance).