passforios/passKit/Helpers/AppError.swift

44 lines
1.3 KiB
Swift
Raw Normal View History

//
// AppError.swift
2021-08-28 07:32:31 +02:00
// passKit
//
// Created by Mingshen Sun on 30/4/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
public enum AppError: Error, Equatable {
case repositoryNotSet
case repositoryRemoteBranchNotFound(branchName: String)
case repositoryBranchNotFound(branchName: String)
case keyImport
case readingFile(fileName: String)
case passwordDuplicated
case gitReset
case gitCreateSignature
case gitPushNotSuccessful
case pgpPublicKeyNotFound(keyID: String)
case pgpPrivateKeyNotFound(keyID: String)
case keyExpiredOrIncompatible
case wrongPassphrase
case wrongPasswordFilename
case decryption
case encryption
case encoding
case unknown
2017-05-11 22:55:08 -07:00
}
extension AppError: LocalizedError {
public var errorDescription: String? {
let enumName = String(describing: self)
let localizationKey = "\(enumName.first!.uppercased())\(enumName.dropFirst().prefix { $0 != "(" })Error."
switch self {
2020-12-18 10:03:47 +01:00
case let .readingFile(name), let .repositoryBranchNotFound(name), let .repositoryRemoteBranchNotFound(name):
return localizationKey.localize(name)
2020-12-18 10:03:47 +01:00
case let .pgpPrivateKeyNotFound(keyID), let .pgpPublicKeyNotFound(keyID):
return localizationKey.localize(keyID)
default:
return localizationKey.localize()
}
}
}