Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeError hook not called on ERR_UNSUPPORTED_PROTOCOL #2294

Open
2 tasks done
alexbepple opened this issue Aug 31, 2023 · 0 comments
Open
2 tasks done

beforeError hook not called on ERR_UNSUPPORTED_PROTOCOL #2294

alexbepple opened this issue Aug 31, 2023 · 0 comments

Comments

@alexbepple
Copy link

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

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant