NetNewsWire/iOS/ErrorHandler.swift

32 lines
744 B
Swift
Raw Normal View History

//
// 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")
2024-05-04 07:32:48 +02:00
public static func present(_ viewController: UIViewController) -> @MainActor (Error) -> () {
return { @MainActor [weak viewController] error in
if UIApplication.shared.applicationState == .active {
viewController?.presentError(error)
} else {
ErrorHandler.log(error)
}
}
}
public static func log(_ error: Error) {
os_log(.error, log: self.log, "%@", error.localizedDescription)
}
}