I'm using Github API. On error (non-200 http status) got
throws an HTTPError which is by default printed like this:
HTTPError: Response code 422 (Unprocessable Entity)
at EventEmitter.<anonymous> (.../node_modules/got/dist/source/as-promise.js:118:31)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
name: 'HTTPError'
}
It gives me no information from the response body to be able to debug the issue (e.g on the local machine, or from the server logs in production).
What I'd like to see is that it'd print the response.body
, e.g by including it in Error.message (maybe limiting the maximum length, for sanity). Now I need to add this code to achieve the needed result:
await got(...)
.catch(err => {
console.log((err as HTTPError).response.body)
})
Then it prints like this:
{"message":"Reference already exists","documentation_url":"https://developer.github.com/v3/git/refs/#create-a-reference"}
And suddenly the error message becomes very useful.
I'm aware that I can use Hooks, extend my got
instance with some error-handling hook to achieve that (that what I'm going to try now). But wouldn't everyone benefit from such feature enabled by default in got
? Or behind a non-default configuration flag?
...
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too