From c6d158a8a344a8e4406a9441e0832dcd29f2c180 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 1 Apr 2022 19:02:36 -0400 Subject: [PATCH] Don't display error message on login cancellation --- .../Screens/Onboarding/OnboardingViewController.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Onboarding/OnboardingViewController.swift b/Tusker/Screens/Onboarding/OnboardingViewController.swift index 2ff330ca..1ee459de 100644 --- a/Tusker/Screens/Onboarding/OnboardingViewController.swift +++ b/Tusker/Screens/Onboarding/OnboardingViewController.swift @@ -93,7 +93,11 @@ class OnboardingViewController: UINavigationController { return try await withCheckedThrowingContinuation({ continuation in self.authenticationSession = ASWebAuthenticationSession(url: authorizeURL, callbackURLScheme: "tusker", completionHandler: { url, error in if let error = error { - continuation.resume(throwing: Error.authenticationSessionError(error)) + if (error as? ASWebAuthenticationSessionError)?.code == .canceledLogin { + continuation.resume(throwing: Error.cancelled) + } else { + continuation.resume(throwing: Error.authenticationSessionError(error)) + } } else if let url = url, let components = URLComponents(url: url, resolvingAgainstBaseURL: true), let item = components.queryItems?.first(where: { $0.name == "code" }), @@ -114,6 +118,7 @@ class OnboardingViewController: UINavigationController { extension OnboardingViewController { enum Error: Swift.Error { + case cancelled case registeringApp(Swift.Error) case authenticationSessionError(Swift.Error) case noAuthorizationCode @@ -122,6 +127,8 @@ extension OnboardingViewController { var localizedDescription: String { switch self { + case .cancelled: + return "Login Cancelled" case .registeringApp(let error): return "Couldn't register app: \(error)" case .authenticationSessionError(let error): @@ -142,6 +149,8 @@ extension OnboardingViewController: InstanceSelectorTableViewControllerDelegate Task { do { try await self.tryLoginTo(instanceURL: instanceURL) + } catch Error.cancelled { + // no-op, don't show an error message } catch let error as Error { let alert = UIAlertController(title: "Error Logging In", message: error.localizedDescription, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Ok", style: .default))