Created
March 22, 2019 14:04
-
-
Save andr3a88/99f641c2cc05d19f854dd11b1646ed60 to your computer and use it in GitHub Desktop.
Catch the decoding error
This file contains 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
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