|
| 1 | +public struct GoogleError: Error, Decodable { |
| 2 | + public let code: Int |
| 3 | + public let message: String |
| 4 | + public let status: String |
| 5 | + public let fcmError: FCMError? |
| 6 | + |
| 7 | + private enum TopLevelCodingKeys: String, CodingKey { |
| 8 | + case error |
| 9 | + } |
| 10 | + |
| 11 | + private enum CodingKeys: String, CodingKey { |
| 12 | + case code, message, status, details |
| 13 | + } |
| 14 | + |
| 15 | + public init(from decoder: Decoder) throws { |
| 16 | + let container = try decoder.container(keyedBy: TopLevelCodingKeys.self) |
| 17 | + .nestedContainer(keyedBy: CodingKeys.self, forKey: .error) |
| 18 | + |
| 19 | + code = try container.decode(Int.self, forKey: .code) |
| 20 | + message = try container.decode(String.self, forKey: .message) |
| 21 | + status = try container.decode(String.self, forKey: .status) |
| 22 | + |
| 23 | + var details = try container.nestedUnkeyedContainer(forKey: .details) |
| 24 | + fcmError = try? details.decode(FCMError.self) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +public struct FCMError: Error, Decodable { |
| 29 | + public let errorCode: ErrorCode |
| 30 | + |
| 31 | + public enum ErrorCode: String, Decodable { |
| 32 | + case unspecified = "UNSPECIFIED_ERROR" |
| 33 | + case invalid = "INVALID_ARGUMENT" |
| 34 | + case unregistered = "UNREGISTERED" |
| 35 | + case senderIDMismatch = "SENDER_ID_MISMATCH" |
| 36 | + case quotaExceeded = "QUOTA_EXCEEDED" |
| 37 | + case apnsAuth = "APNS_AUTH_ERROR" |
| 38 | + case unavailable = "UNAVAILABLE" |
| 39 | + case `internal` = "INTERNAL" |
| 40 | + } |
| 41 | +} |
0 commit comments