2019-05-26 18:54:32 +02:00
|
|
|
//
|
|
|
|
// ErrorHandler.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 5/26/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import os.log
|
|
|
|
|
|
|
|
struct ErrorHandler {
|
|
|
|
|
2024-05-04 07:32:48 +02:00
|
|
|
nonisolated(unsafe) private static let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
2019-05-26 18:54:32 +02:00
|
|
|
|
2024-05-04 07:32:48 +02:00
|
|
|
public static func present(_ viewController: UIViewController) -> @MainActor (Error) -> () {
|
|
|
|
|
2024-03-20 03:55:55 +01:00
|
|
|
return { @MainActor [weak viewController] error in
|
2019-11-05 03:24:21 +01:00
|
|
|
if UIApplication.shared.applicationState == .active {
|
|
|
|
viewController?.presentError(error)
|
|
|
|
} else {
|
|
|
|
ErrorHandler.log(error)
|
|
|
|
}
|
2019-06-27 21:21:07 +02:00
|
|
|
}
|
2019-05-26 18:54:32 +02:00
|
|
|
}
|
2019-06-27 21:21:07 +02:00
|
|
|
|
2019-05-26 18:54:32 +02:00
|
|
|
public static func log(_ error: Error) {
|
|
|
|
os_log(.error, log: self.log, "%@", error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|