I had a BeforeErrorHook that in got@10 had err.response defined, so I used err.response.body to display/format error. In got@11 the same code tells me that err.response.body is undefined.
Briefly:
export function gotErrorHook(): BeforeErrorHook {
return err => {
console.log(err instanceof HTTPError, err.response.body)
//=> true, undefined
err.response.body to be defined
Can you set up a full example of the bug?
We have many tests that prove it's defined, for example: https://github.com/sindresorhus/got/blob/1f6ac4597b797e6fe760a7dc11a3db8bf298aa94/test/error.ts#L20
but since Got has been fully rewrited to utilize the native streams new bugs may occur.
Can you set up a full example of the bug?
Yep. But first - am I supposed to have err.response defined? Like, this API didn't suppose to change or anything? I noticed the change from GotError to RequestError, but both have .response attached.
We have many tests that prove it's defined, for example:
https://github.com/sindresorhus/got/blob/1f6ac4597b797e6fe760a7dc11a3db8bf298aa94/test/error.ts#L20
but since Got has been fully rewrited to utilize the native streams new bugs may occur.
I see. I'll try to hack together a minimal repro.. Hold on..
But first - am I supposed to have err.response defined?
Yep. All RequestErrors should have a .response defined (if the underlying Node.js request emitted it) except for some invalid usage errors.
The HTTPError should always have a .response property.
Ok, classic thing, minimal repro gives me .response as defined. I probably did something wrong in my first try. But, the question propagates to err.response.body, which is undefined now and it wasn't if I run the same code against got@10. Here's the got@11 minimal repro:
https://runkit.com/kirillgroshkov/5e9dbf8b5ca48500131a30b8
It logs err.response.body as undefined
Same code with got@10: https://runkit.com/kirillgroshkov/5e9dc3019747cc001a89d84c
Ok, I know how to fix this, give me 15 mins.
I've encountered another problem. I passed only one beforeError hook, and there are two (options.hooks.beforeError.length). Weird...
Fixed in d914a7e7a0d97b03745b9b47623e4ac3532b4dae
Released 11.0.1, thanks for reporting!