Error presenter: Always handle the passed error
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
046b540e53
commit
7631844fbe
|
@ -5,7 +5,7 @@ import UIKit
|
||||||
import os.log
|
import os.log
|
||||||
|
|
||||||
class ErrorPresenter {
|
class ErrorPresenter {
|
||||||
static func errorMessage(for error: Error) -> (String, String)? {
|
static func errorMessage(for error: Error) -> (String, String) {
|
||||||
switch (error) {
|
switch (error) {
|
||||||
|
|
||||||
// TunnelManagementError
|
// TunnelManagementError
|
||||||
|
@ -43,15 +43,14 @@ class ErrorPresenter {
|
||||||
return ("Nothing to export", "There are no tunnels to export")
|
return ("Nothing to export", "There are no tunnels to export")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
os_log("ErrorPresenter: Error not presented: %{public}@", log: OSLog.default, type: .error, "\(error)")
|
return ("Error", error.localizedDescription)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func showErrorAlert(error: Error, from sourceVC: UIViewController?,
|
static func showErrorAlert(error: Error, from sourceVC: UIViewController?,
|
||||||
onDismissal: (() -> Void)? = nil, onPresented: (() -> Void)? = nil) {
|
onDismissal: (() -> Void)? = nil, onPresented: (() -> Void)? = nil) {
|
||||||
guard let sourceVC = sourceVC else { return }
|
guard let sourceVC = sourceVC else { return }
|
||||||
guard let (title, message) = ErrorPresenter.errorMessage(for: error) else { return }
|
let (title, message) = ErrorPresenter.errorMessage(for: error)
|
||||||
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
|
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
|
||||||
onDismissal?()
|
onDismissal?()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue