2023-01-15 12:41:55 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
2023-03-28 10:35:38 +02:00
|
|
|
// Licensed under the Apache License 2.0.
|
2023-01-15 12:41:55 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2023-02-21 21:37:38 +01:00
|
|
|
import PixelfedKit
|
2023-01-15 12:41:55 +01:00
|
|
|
|
|
|
|
public class ErrorService {
|
|
|
|
public static let shared = ErrorService()
|
|
|
|
private init() { }
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-01-15 12:41:55 +01:00
|
|
|
public func handle(_ error: Error, message: String, showToastr: Bool = false) {
|
|
|
|
if showToastr {
|
2023-02-21 22:41:20 +01:00
|
|
|
switch error {
|
|
|
|
case is NetworkError, is URLError:
|
|
|
|
ToastrService.shared.showError(title: message, subtitle: error.localizedDescription)
|
|
|
|
default:
|
2023-02-21 21:37:38 +01:00
|
|
|
ToastrService.shared.showError(subtitle: message)
|
|
|
|
}
|
2023-01-15 12:41:55 +01:00
|
|
|
}
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-03-13 13:53:36 +01:00
|
|
|
let localizedMessage = NSLocalizedString(message, comment: "Error message")
|
|
|
|
print("Error ['\(localizedMessage)']: \(error.localizedDescription)")
|
2023-01-15 12:41:55 +01:00
|
|
|
}
|
|
|
|
}
|