Closed RavenHursT closed 2 years ago
Well, was trying to find the reason behind the 422 response and found that
got
throws on non 2xx/3xx response codes, but worse than that, it just swallows the response object, and only throws a customHTTPError
object w/ just two properties:
The info you are looking for is in error.response.body
where error
is the error you are receiving. There are multiple closed issues about this. Feel free to open a PR to document it.
I kept seeing a
422 Unprocessable Entity
error getting thrown from thestriptTags
API while using this lib.So I drilled down into the source and saw that the lib being used to make requests is
got
(first I've ever heard ofgot
BTW).Well, was trying to find the reason behind the 422 response and found that
got
throws on non 2xx/3xx response codes, but worse than that, it just swallows the response object, and only throws a customHTTPError
object w/ just two properties:https://github.com/sindresorhus/got/blob/4f24bd11fb50757ec8753a74e4a7b18de95ba155/source/core/errors.ts#L97-L101
So when I was trying to introspect the body of the response, I was out of luck, there's no way to get ahold of that in a
catch
scope when all that's passed in is theHTTPError
.I had to manually construct the request and fire it off in an HTTP client, just so I could find out what was actually wrong.
This is beyond frustrating. Either find a way to give the consumer of this a way to get a handle on the response object, or else just use
fetch
and return the nativeResponse
object. Then at least we'd be able to read the body stream and parse it ourselves. What isn't acceptable is for a lib to just swallow useful data just because a certain span of response codes were returned.