Closed piotrjaromin closed 3 years ago
Untill version 11.5.0 hooks.beforeError was able to return modified error instance, but after bump to 11.6.0 this is functionality is lost, error returned is always RequestError from got library.
hooks.beforeError
RequestError
If I am correct the overridden error comes from this line: https://github.com/sindresorhus/got/blob/49c16ee54fb19ea7aa77e24ac8c2b602f0aad265/source/core/index.ts#L2708
errors returned by before hook are NOT propagated to caller
errors returned by before hook propagated to caller
const got = require('got'); class CustomError extends Error {} got('https://api.github.com/some-endpoint', { hooks: { beforeError: [err => { console.log('Mapping to custom one:', err.message); return new CustomError(); }], }, }) .then(() => console.log('Error was not thrown')) // <- will not be logged // Below line for got: // 11.5.0: Got error: CustomError // 11.6.0: Got error: RequestError .catch(err => console.log('Got error:', err.constructor.name)); ...
I have exactly the same actual/expected behavior on:
I agree that it would be great to see this feature. There is already an issue about this.
Duplicate of #1353
Describe the bug
Untill version 11.5.0
hooks.beforeError
was able to return modified error instance, but after bump to 11.6.0 this is functionality is lost, error returned is alwaysRequestError
from got library.If I am correct the overridden error comes from this line: https://github.com/sindresorhus/got/blob/49c16ee54fb19ea7aa77e24ac8c2b602f0aad265/source/core/index.ts#L2708
Actual behavior
errors returned by before hook are NOT propagated to caller
Expected behavior
errors returned by before hook propagated to caller
Code to reproduce
Checklist