Should reject return response vs err?
eddywashere opened this issue · 6 comments
Any reason why a generic error is returned vs just the response?
use case: I'd like to use the original response to throw a custom error.
What do you mean by "just the response"? This module is meant to reject invalid HTTP statuses.
Here's an example of what I'm using currently:
req.after(function(res) {
if (res.status >= lower && res.status <= upper) {
return Promise.resolve(res);
}
return Promise.reject(res);
});
From here I can catch errors and access things like the response body that could include things like valuable error messages re: missing parameter name
.
You should be able to do that already. By rejecting using the built in res.error
function, it's added a popsicle
property for you to access. Try something like error.popsicle.response.<blah>
?
Here's the documentation: https://github.com/blakeembrey/popsicle#error-handling. This module should probably update to the proper 1.0 API though, so I can make a minor release for that (E.g. providing the type
).
@eddywashere I made some tweaks and improved the README. Let me know if the information I provided solves the issue for you, or if I've interpreted your need incorrectly.
👍 thanks for the quick responses