MaikuB / MaikuB/flutter_appauth
[Proposal] Expose better error code
Nobody has claimed this yet.
- Dominant language
- Objective-C
- Stars
- 308
- Forks
- 301
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 5
Description
## 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how authorizeAndExchangeCode turns iOS NSError and Android AuthorizationException into PlatformException. Review the existing handling for the hard-coded method-based code and determine how the underlying domain/code or type/code is currently available. Done means both platforms expose that underlying error information instead of the method name, including cancellation details.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, ios, objective-c
- Domain
- authentication, mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100