got
got copied to clipboard
beforeError hook not called on ERR_UNSUPPORTED_PROTOCOL
Describe the bug
- Got version: 12.6.1 & 13.0.0
- Node.js version: 18.17.1 & 20.5.1
- OS & version: macOS Ventura 13.1
Actual behavior
When POSTing to an URL with an unsupported protocol, the beforeError
hook is not called.
Expected behavior
The beforeError
hook should be called just like with other errors, e.g. ERR_NON_2XX_3XX_RESPONSE
.
Code to reproduce
import got from "got";
const redactAuthorizationHeader = (error) => {
error.options.headers.authorization = "<redacted>";
error.options._init[0].headers.authorization = "<redacted>";
return error;
};
const post = (payload) =>
got
.post(`xhttps://www.example.com/some/resource`, {
headers: { authorization: `Bearer secret` },
json: payload,
hooks: { beforeError: [redactAuthorizationHeader] },
})
.json();
await post({ foo: 42 });
Checklist
- [x] I have read the documentation.
- [x] I have tried my code with the latest version of Node.js and Got.