passforios/passKit/Helpers/AppError.swift

37 lines
990 B
Swift
Raw Normal View History

//
// AppError.swift
// pass
//
// Created by Mingshen Sun on 30/4/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
public enum AppError: Error {
case RepositoryNotSet
case RepositoryRemoteBranchNotFound(_: String)
2019-01-06 20:10:47 +01:00
case RepositoryBranchNotFound(_: String)
case KeyImport
case ReadingFile(_: String)
case PasswordDuplicated
case GitReset
2019-06-09 22:18:54 -07:00
case GitCommit
case PasswordEntity
case PgpPublicKeyNotExist
2017-10-15 21:37:00 +08:00
case WrongPasswordFilename
case Decryption
2019-06-09 22:18:54 -07:00
case Encryption
case Unknown
2017-05-11 22:55:08 -07:00
}
extension AppError: LocalizedError {
public var errorDescription: String? {
let localizationKey = "\(String(describing: self).prefix(while: { $0 != "(" }))Error."
switch self {
case let .RepositoryRemoteBranchNotFound(name), let .RepositoryBranchNotFound(name), let .ReadingFile(name):
return localizationKey.localize(name)
default:
return localizationKey.localize()
}
}
}