Problem
Currently, when AppAuth
failed, the plugin throws PlatformException
.
The code
of PlatformException
is hardcoded to a certain value based on which method the app called, which isn't very useful. As the app should have know which API is called. Instead the actual useful information isn't passed up.
For example, if app calls authorizeAndExchangeCode
, and then user canceled the web view popped up.
On iOS:
PlatformException(authorize_and_exchange_code_failed, Failed to authorize: The operation couldn’t be completed. (org.openid.appauth.general error -3.), null, null)
The code authorize_and_exchange_code_failed
is useless as we have known we called authorizeAndExchangeCode
.
The useful bit is actually org.openid.appauth.general
and -3
, which is the code
and domain
of the NSError
underneath, but it is mixed in the message that passed up.
on Android:
Error: PlatformException(authorize_and_exchange_code_failed, Failed to authorize: [error: null, description: User cancelled flow], null, null)
Again authorize_and_exchange_code_failed
is not helpful. User cancelled flow
is the one useful. And we missed some extra information here.
Proposal
When throw PlatformException from plugin, rather than returns hard coded thing that bind to the calling method. Expose the more detail from underneath error.
For iOS:
Use the concat the NSError
's domain
and code
as the PlatformException error code. So it would return org.openid.appauth.general -3
instead of authorize_and_exchange_code_failed
as code.
And for Android:
The AppAuth would throws AuthorizationException
, which contains type
and code
. return the type
and code
accordingly.