-
Notifications
You must be signed in to change notification settings - Fork 297
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
Allow parsing of error object by given transform #86
Comments
Hi @Limess good point. Thinking about that I have several APIs I call which usually return JSON but HTML for e.g. a 404. In this case the transform function would need to check the |
@analog-nico Problems do still arise however. We're dealing with APIs which always return JSON. There's a current case when they return non-400s and we use the Admittedly that could be done by catching the error and re-throwing appropriately, but it's caught us out that we get unintelligible error messages with non-200s by default, and it may be useful to have an optional transform in this specific case. It'd be nice to have your thoughts on how to handle these scenarios from an error handling point of view! |
I can't really tell what is better because I do not use the transform feature personally. But since |
Hi @Limess quick question: What do you think about adding a I see the advantage that (1) it is backwards compatible and (2) if the API returns a weird response the transform function could crash without screwing up the response handling. ( As a disadvantage I see the inconsistent API. Alternatively, we could put the transformed response into |
I just released request-promise@3.0.0 which solves this issue.
|
request-promise
doesn't seem to apply the givenoptions.transform
function to theresponse
object attached to aStatusCodeError
.I'd expect that transform to be applied, given the relation implied by "Rejected promises and the simple option" example. In this case, the standard
request
library would have parsed the request body before it was filtered by status code. The response at this point is not an error with the request so I see no gain in not parsing the response.I realise this would be a breaking change, so was wondering if it would be of interest to pass an additional option to enable this behaviour?
For example, something along the lines of
Thanks
The text was updated successfully, but these errors were encountered: