Skip to content

Instantly share code, notes, and snippets.

@andr3a88
Created March 22, 2019 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andr3a88/99f641c2cc05d19f854dd11b1646ed60 to your computer and use it in GitHub Desktop.
Save andr3a88/99f641c2cc05d19f854dd11b1646ed60 to your computer and use it in GitHub Desktop.
Catch the decoding error
let decoder = RPJSONDecoder()
do {
let response = try decoder.decode(BaseDataArrayResponse<T>.self, from: json)
completion(response.data, nil)
} catch let DecodingError.dataCorrupted(context) {
completion(nil, DecodingError.dataCorrupted(context))
print("codingPath:", context.codingPath)
} catch let DecodingError.typeMismatch(type, context) {
completion(nil, DecodingError.typeMismatch(type, context))
print("Type '\(type)' mismatch:", context.debugDescription)
print("codingPath:", context.codingPath)
} catch let error {
completion(nil, error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment