How to get error response body in beforeRetry hook ?
i am getting error.response.statusCode fine but not getting error.response.body ?
I have read the documentation. no mention of how to get error body ?
sample code to generate the issue
const got = require("got")
got(errorUrl, {
hooks: {
beforeRetry: [
(options, error, retryCount) => {
console.log(error.response.statusCode) //408
console.log(error.response.body) // undefined [issue] Expected : this is 408 error body
},
],
},
})
the php code i used to generate error is below errorUrl.
<?php
header('HTTP/1.1 408');
echo 'this is 408 error body';
?>
Reproducible:
const got = require("got");
const server = require('http').createServer((request, response) => {
response.statusCode = 500;
response.end('nope');
});
server.listen(() => {
got(`http://localhost:${server.address().port}`, {
hooks: {
beforeRetry: [
(options, error, retryCount) => {
console.log(error.response.statusCode) //408
console.log(error.response.body) // undefined [issue] Expected : this is 408 error body
},
],
},
}).catch(() => {});
});
Is this happening with a specific version of Node or the Library?
When I cloned down got added the reproducible code into a test.js file and ran it I got nope back for error.response.body

hi,
my version is same "got": "11.5.2", node v12.10.0, os windows 10 64 bit
i am not getting body?

It seems to be fixed in the master branch since commit https://github.com/sindresorhus/got/commit/707219825b2f8ff3df597230a53244636df21642
Ah yes, the _beforeError is removed for Promise API and therefore it defines the body here:
Most helpful comment
It seems to be fixed in the master branch since commit https://github.com/sindresorhus/got/commit/707219825b2f8ff3df597230a53244636df21642