Improves handling of authentication errors
This commit is contained in:
parent
84e44f5aee
commit
df7a8df19a
@ -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!
|
||||||
@ -75,11 +77,23 @@ extension LaunchViewController
|
|||||||
|
|
||||||
override func handleLaunchError(_ error: Error)
|
override func handleLaunchError(_ error: Error)
|
||||||
{
|
{
|
||||||
let alertController = UIAlertController(title: NSLocalizedString("Unable to Launch Delta", comment: ""), message: error.localizedDescription, preferredStyle: .alert)
|
do
|
||||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Retry", comment: ""), style: .default, handler: { (action) in
|
{
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
catch is HarmonyError
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
self.handleLaunchConditions()
|
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()
|
override func finishLaunching()
|
||||||
|
|||||||
@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user