| 1 | import Foundation |
| 2 | |
| 3 | /// An error returned by the smbCloud Auth API. |
| 4 | /// |
| 5 | /// Mirrors `smbcloud_model::error_codes::ErrorResponse::Error { error_code, |
| 6 | /// message }` from the canonical SDK. |
| 7 | public struct SmbCloudError: Error, Sendable, Equatable { |
| 8 | public let code: SmbCloudErrorCode |
| 9 | public let message: String |
| 10 | |
| 11 | public init(code: SmbCloudErrorCode, message: String? = nil) { |
| 12 | self.code = code |
| 13 | self.message = message ?? code.defaultMessage |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | extension SmbCloudError: LocalizedError { |
| 18 | public var errorDescription: String? { message } |
| 19 | } |
| 20 | |
| 21 | /// Mirrors `smbcloud_model::error_codes::ErrorCode` (the `i32`-repr enum). |
| 22 | public enum SmbCloudErrorCode: Int, Sendable, Equatable { |
| 23 | // Generic |
| 24 | case unknown = 0 |
| 25 | case parseError = 1 |
| 26 | case networkError = 2 |
| 27 | case inputError = 3 |
| 28 | case missingConfig = 4 |
| 29 | case cancel = 5 |
| 30 | // Account / access |
| 31 | case unauthorized = 100 |
| 32 | case invalidParams = 101 |
| 33 | // Account-not-ready |
| 34 | case emailNotFound = 1000 |
| 35 | case emailNotVerified = 1001 |
| 36 | case emailConfirmationFailed = 1002 |
| 37 | case passwordNotSet = 1003 |
| 38 | case gitHubEmailNotConnected = 1004 |
| 39 | case emailAlreadyExist = 1005 |
| 40 | case invalidPassword = 1006 |
| 41 | // Projects |
| 42 | case projectNotFound = 2000 |
| 43 | case unsupportedRunner = 2001 |
| 44 | |
| 45 | public var defaultMessage: String { |
| 46 | switch self { |
| 47 | case .unknown: return "Unknown error." |
| 48 | case .parseError: return "Parse error." |
| 49 | case .networkError: |
| 50 | return "Network error. Please check your internet connection and try again." |
| 51 | case .inputError: return "Input error." |
| 52 | case .missingConfig: return "Missing config." |
| 53 | case .cancel: return "Cancelled." |
| 54 | case .unauthorized: return "Unauthorized access." |
| 55 | case .invalidParams: return "Invalid parameters." |
| 56 | case .emailNotFound: return "Email not found." |
| 57 | case .emailNotVerified: return "Email not verified." |
| 58 | case .emailConfirmationFailed: return "Email confirmation failed." |
| 59 | case .passwordNotSet: return "Password is not set." |
| 60 | case .gitHubEmailNotConnected: return "GitHub email is not connected." |
| 61 | case .emailAlreadyExist: return "Email already exists." |
| 62 | case .invalidPassword: return "Invalid password." |
| 63 | case .projectNotFound: return "Project not found." |
| 64 | case .unsupportedRunner: return "Unsupported runner." |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /// Account-status error codes used inside ``AccountStatus/incomplete(status:)``. |
| 70 | /// |
| 71 | /// Mirrors `smbcloud_model::account::ErrorCode` (the `u32`-repr enum), which is |
| 72 | /// distinct from ``SmbCloudErrorCode``. |
| 73 | public enum AccountErrorCode: Int, Sendable, Equatable { |
| 74 | case emailNotFound = 1000 |
| 75 | case emailUnverified = 1001 |
| 76 | case emailConfirmationFailed = 1002 |
| 77 | case passwordNotSet = 1003 |
| 78 | case githubNotLinked = 1004 |
| 79 | case emailAlreadyExist = 1005 |
| 80 | case invalidPassword = 1006 |
| 81 | case hostedMailAccountUnverified = 1007 |
| 82 | } |