Created
July 20, 2020 05:17
-
-
Save charlesmuchene/942a0b835e740e9009d0abd92e8344eb to your computer and use it in GitHub Desktop.
Api error entity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct APIError: Error, Decodable, CustomStringConvertible { | |
| let code: Int | |
| let message: String | |
| let errors: [String] = [] // May be dictionary?? | |
| static let genericResponseError = APIError(code: 500, message: "Error getting response") | |
| static let noResponseError = APIError(code: 500, message: "No response from server") | |
| var description: String { "ApiError -> Code: \(code), Message: \(message), Errors: \(errors)" } | |
| init(code: Int, message: String) { | |
| self.code = code | |
| self.message = message | |
| } | |
| init(error: Error?) { | |
| self.code = 500 | |
| self.message = error?.localizedDescription ?? APIError.genericResponseError.message | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment