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 Roxas
import Harmony
class LaunchViewController: RSTLaunchViewController
{
@IBOutlet private var gameViewContainerView: UIView!
@ -75,11 +77,23 @@ extension LaunchViewController
override func handleLaunchError(_ error: Error)
{
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
do
{
throw error
}
catch is HarmonyError
{
// Ignore
self.handleLaunchConditions()
}))
self.present(alertController, animated: true, completion: nil)
}
catch
{
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
self.handleLaunchConditions()
}))
self.present(alertController, animated: true, completion: nil)
}
}
override func finishLaunching()

View File

@ -124,11 +124,39 @@ extension SyncManager
_ = try result.get()
self.coordinator = coordinator
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
{
print("SyncManager.start error:", error)
completionHandler(.failure(error))
}
}