Impressia/Vernissage/Services/ErrorsService.swift

28 lines
852 B
Swift

//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the Apache License 2.0.
//
import Foundation
import PixelfedKit
public class ErrorService {
public static let shared = ErrorService()
private init() { }
public func handle(_ error: Error, message: String, showToastr: Bool = false) {
if showToastr {
switch error {
case is NetworkError, is URLError:
ToastrService.shared.showError(title: message, subtitle: error.localizedDescription)
default:
ToastrService.shared.showError(subtitle: message)
}
}
let localizedMessage = NSLocalizedString(message, comment: "Error message")
print("Error ['\(localizedMessage)']: \(error.localizedDescription)")
}
}