43 lines
953 B
Swift
43 lines
953 B
Swift
//
|
|
// AppError.swift
|
|
// HRW
|
|
//
|
|
// Created by Isaac Paul on 10/13/24.
|
|
// Non-commercial license, see LICENSE.MD in the project root for details
|
|
//
|
|
|
|
import Foundation
|
|
|
|
final class AppError: LocalizedError, Sendable, CustomStringConvertible {
|
|
var description: String { get {message}}
|
|
|
|
|
|
let message: String
|
|
|
|
init(_ message: String) {
|
|
self.message = message
|
|
}
|
|
init(_ message: String, _ error:Error) {
|
|
self.message = "\(message) : \(error.localizedDescription)"
|
|
}
|
|
|
|
static func failure<T>(_ message: String) -> Result<T, AppError> {
|
|
return .failure(AppError(message))
|
|
}
|
|
|
|
var errorDescription: String? {
|
|
get {
|
|
return message
|
|
}
|
|
}
|
|
|
|
/// A localized message describing the reason for the failure.
|
|
var failureReason: String? { get { message } }
|
|
|
|
var localizedDescription: String? {
|
|
get {
|
|
message
|
|
}
|
|
}
|
|
}
|