Skip to content

Instantly share code, notes, and snippets.

@charlesmuchene
Created July 20, 2020 05:17
Show Gist options
  • Select an option

  • Save charlesmuchene/942a0b835e740e9009d0abd92e8344eb to your computer and use it in GitHub Desktop.

Select an option

Save charlesmuchene/942a0b835e740e9009d0abd92e8344eb to your computer and use it in GitHub Desktop.
Api error entity
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