New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better exception message when throwing MalformedResponse #17
Comments
The malformed error means different things depending on which Deserializer you are using (the old JSON or the Swift4 Codable way for JSON). Can you post some sample code? |
As for getting the raw Data object: do {
let response = try result.value()
// ...
} catch NetworkingError.malformedResponse(let data) {
print("Error performing GET, malformed data response: \(data!)")
} The |
First of all, thanks for such a quick answer! After some source code digging, I found out that the Exception has the data, but I didn't know how to get it. Thanks a lot! About the Deserializer, I'm using only Swift 4's Codable for now. Some example:
Probably there is a better way to do what I'm doing, but I'm already very happy for now. Is there any way to get an exception message that indicates what key is missing in the JSON response, or something like that, that narrows my search for API misbehavior? |
It should already be logging the error that comes straight from the Swift API. If you look at the. print("Error decoding to JSON object \(error.localizedDescription)") I am not sure how detailed the built-in decoder's errors are, but take a look there. You can breakpoint in there and see if there are different details in the error that isn't being logged out. If you find something else that I should log out, let me know. |
@vitorhugods Take a look at the last commit: 43b15f2 I changed the Deserializers so they no longer swallow error, but instead pass them back up. Now when you try to get the Thanks! |
Seems really good to me. Really liked it. =) Also, I've been thinking here about debugging and reports. |
Ok, I'll start getting 4.0.2 released soon. As for Firebase/Crashyltics, that would be integrated at the app level, not in the library. Thanks for the suggestion on the error improvements! |
I'm not saying it should not be in the app level. But so far, the way to get the raw response body in order to log or report, without deserializing is when an serializing error occurs, as seen here. Or is there any other way to get that? |
4.0.2 has been released and contains better error handling for Deserializers and it also removes the optional on the As of now, there is no way to get the raw data back in a success case. There are some memory constraints with doing this. Imagine using an Image Deserializer on very large raw images, you would be using twice as much memory, which is probably not desirable. Or worse yet, maybe you used a Movie Deserializer. If you use the built-in |
Understood. I've never though of images and videos. |
@vitorhugods going to close now that the 4.0.2 release include much better error handling. Thanks a ton for bringing the issue to my attention. |
It is very hard to find where is the malformed part of a response when dealing with a big JSON.
Would be nice if a more specific message was shown, like "Could not find "key" in the JSON".
And also, I couldn't find a way to get the raw text response and print it to help me debug.
Thanks for the library. I really wish I could be of more help, but I'm learning Swift.
The text was updated successfully, but these errors were encountered: