Closed alladinian closed 7 years ago
Hello @alladinian! What you are looking for is this:
/**
Custom error handler block, to parse error returned in response body.
For example: `{ error: { code: 1, message: "Server error" } }`
*/
open var errorHandler: ((JSON) -> Error?)? = nil
just set your custom closure on the ws
and the call should fail if it returns an Error
.
How did I miss that... @maxkonovalov Thanks man 🍻
Hi there,
Given that is common for a lot of APIs to return valid JSON responses with (business) errors that are described in the body (alà
success = false
) with a 200 status code, would it be possible maybe to open functions likehandleJSONResponse
etc in order to override in a subclass and thus rejecting accordingly? (The point being to treat both system & business errors as reason for rejection in a chain)Unless I am missing some other way to do that transparently...
Any thoughts?