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
|
2025-10-02 08:54:48 -07:00
|
|
|
import os
|
2019-05-26 11:54:32 -05:00
|
|
|
import RSCore
|
|
|
|
|
|
2025-11-17 21:53:40 -08:00
|
|
|
struct ErrorHandler: Sendable {
|
2019-05-26 11:54:32 -05:00
|
|
|
|
2025-10-02 08:54:48 -07:00
|
|
|
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ErrorHandler")
|
2019-05-26 11:54:32 -05:00
|
|
|
|
2026-01-02 15:58:36 -08:00
|
|
|
@Sendable public static func present(_ viewController: UIViewController) -> @Sendable (Error) -> Void {
|
2019-06-27 14:21:07 -05:00
|
|
|
return { [weak viewController] error in
|
2025-11-17 14:25:56 -08:00
|
|
|
Task { @MainActor in
|
|
|
|
|
if UIApplication.shared.applicationState == .active {
|
|
|
|
|
viewController?.presentError(error)
|
|
|
|
|
} else {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2025-11-17 14:25:56 -08:00
|
|
|
@Sendable nonisolated public static func log(_ error: Error) {
|
2025-10-02 08:54:48 -07:00
|
|
|
logger.error("\(error.localizedDescription)")
|
|
|
|
|
}
|
2019-05-26 11:54:32 -05:00
|
|
|
}
|