Closed mAd-DaWg closed 6 years ago
If the response is a 404 and the body can not be parsed, what is the expectation? This seems to work as expected. If you’d like it to error on a non-2xx status code, there’s a plugin for that - but it doesn’t by default. If there’s some other behaviour you desire, you could also wrap the function in your own behaviour to parse on this or do something else when failed.
the expectation is to get the 404 response, not a parse error, as the plugins are tacked onto every request. The plugins should not break regular functionality
Exactly! They are for every request, even non-2xx. If you want custom handling, it's really simple - just write something that goes one way or the other - parses or doesn't parse. It doesn't come with that built in, but could in the future - the reason for not building it in is that if you're using JSON parse you're expecting a JSON response. You're not getting a JSON response though, so it makes sense to error.
Let's start with what you want to happen here, then I can help find the right solution. Right now I still don't know what you want, sorry. You do a req -> 200 -> parse
and, what, req -> 404 -> not parse
or req -> 404 -> error
? The normal way I'd handle this is with https://www.npmjs.com/package/popsicle-status, since I don't want to handle 4xx or 5xx like the rest of the application.
The "req -> 404 -> not parse" route, but i will look at the status package
when i tack on
.use(popsicle.plugins.parse(['json',
'urlencoded']))` to a popsicle request, if the url is not found, it results in a EPARSE error. If I don't tack on the parsers, it gives the appropriate error/server response...