Improves handling of authentication errors

This commit is contained in:
Riley Testut 2019-03-25 15:46:39 -07:00
parent 84e44f5aee
commit df7a8df19a
2 changed files with 47 additions and 5 deletions

View File

@ -9,6 +9,8 @@
import UIKit import UIKit
import Roxas import Roxas
import Harmony
class LaunchViewController: RSTLaunchViewController class LaunchViewController: RSTLaunchViewController
{ {
@IBOutlet private var gameViewContainerView: UIView! @IBOutlet private var gameViewContainerView: UIView!
@ -74,6 +76,17 @@ extension LaunchViewController
} }
override func handleLaunchError(_ error: Error) override func handleLaunchError(_ error: Error)
{
do
{
throw error
}
catch is HarmonyError
{
// Ignore
self.handleLaunchConditions()
}
catch
{ {
let alertController = UIAlertController(title: NSLocalizedString("Unable to Launch Delta", comment: ""), message: error.localizedDescription, preferredStyle: .alert) let alertController = UIAlertController(title: NSLocalizedString("Unable to Launch Delta", comment: ""), message: error.localizedDescription, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("Retry", comment: ""), style: .default, handler: { (action) in alertController.addAction(UIAlertAction(title: NSLocalizedString("Retry", comment: ""), style: .default, handler: { (action) in
@ -81,6 +94,7 @@ extension LaunchViewController
})) }))
self.present(alertController, animated: true, completion: nil) self.present(alertController, animated: true, completion: nil)
} }
}
override func finishLaunching() override func finishLaunching()
{ {

View File

@ -124,11 +124,39 @@ extension SyncManager
_ = try result.get() _ = try result.get()
self.coordinator = coordinator self.coordinator = coordinator
completionHandler(.success) completionHandler(.success)
} }
catch let authError as AuthenticationError
{
// Authentication failed, but otherwise started successfully so still assign self.coordinator.
self.coordinator = coordinator
switch authError
{
case .other(ServiceError.connectionFailed):
// Authentication failed due to network connection, but otherwise started successfully so we ignore this error.
completionHandler(.success)
default:
// Another authentication error occured, so we'll deauthenticate ourselves.
print("SyncManager.start auth error:", authError)
self.deauthenticate() { (result) in
switch result
{
case .success:
completionHandler(.success)
case .failure:
// authError is more useful than result's error.
completionHandler(.failure(authError))
}
}
}
}
catch catch
{ {
print("SyncManager.start error:", error)
completionHandler(.failure(error)) completionHandler(.failure(error))
} }
} }