Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user canceled "error" in demo app #762

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AuthenticationServices
import WebKit
import WordPressAuthenticator
import WordPressKit
Expand Down Expand Up @@ -96,6 +97,12 @@ extension ViewController {
)
} catch let error as OAuthError {
presentAlert(title: "❌", message: error.errorDescription, onDismiss: {})
} catch let error as NSError where
error.domain == ASWebAuthenticationSessionError.errorDomain
&& error.code == ASWebAuthenticationSessionError.Code.canceledLogin.rawValue {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I you ask Xcode, it will indent this as:

            } catch let error as NSError where
                        error.domain == ASWebAuthenticationSessionError.errorDomain
                        && error.code == ASWebAuthenticationSessionError.Code.canceledLogin.rawValue {

That doesn't make any sense to me, so I updated it manually.

// In a production app, the UX would be better if we didn't present an alert.
// But here, it's useful to show it to make the error handling visible for reference.
presentAlert(title: "", message: "User cancelled", onDismiss: {})
} catch {
fatalError("Caught an error that was not of the expected `OAuthError` type: \(error)")
}
Expand Down