2019-05-26 11:54:32 -05:00
|
|
|
//
|
|
|
|
|
// ErrorHandler.swift
|
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
|
//
|
|
|
|
|
// Created by Maurice Parker on 5/26/19.
|
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import RSCore
|
|
|
|
|
|
2022-08-03 15:37:12 +08:00
|
|
|
struct ErrorHandler: Logging {
|
2019-05-26 11:54:32 -05:00
|
|
|
|
2019-06-27 14:21:07 -05:00
|
|
|
public static func present(_ viewController: UIViewController) -> (Error) -> () {
|
|
|
|
|
return { [weak viewController] error in
|
2019-11-04 20:24:21 -06:00
|
|
|
if UIApplication.shared.applicationState == .active {
|
|
|
|
|
viewController?.presentError(error)
|
|
|
|
|
} else {
|
2022-08-03 15:37:12 +08:00
|
|
|
log(error)
|
2019-11-04 20:24:21 -06:00
|
|
|
}
|
2019-06-27 14:21:07 -05:00
|
|
|
}
|
2019-05-26 11:54:32 -05:00
|
|
|
}
|
2019-06-27 14:21:07 -05:00
|
|
|
|
2019-05-26 11:54:32 -05:00
|
|
|
public static func log(_ error: Error) {
|
2022-08-03 15:37:12 +08:00
|
|
|
ErrorHandler.logger.error("\(error.localizedDescription, privacy: .public)")
|
2019-05-26 11:54:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|