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

interceptors.responseError doesn't work with MockAgent #3928

Closed
Gigioliva opened this issue Dec 7, 2024 · 2 comments · Fixed by #3931
Closed

interceptors.responseError doesn't work with MockAgent #3928

Gigioliva opened this issue Dec 7, 2024 · 2 comments · Fixed by #3931
Labels
bug Something isn't working

Comments

@Gigioliva
Copy link
Contributor

interceptors.responseError doesn't work with MockAgent

In version 7.0.0, the throwOnError option was removed.
Here is indicated to use the interceptor interceptors.responseError to get the same behavior as before. This solution seems to work when calling a real endpoint. However, this does not work in the test environment using the MockAgent.

Reproducible By

Here a code example (an example extracted from a test case):

import { MockAgent, Pool, interceptors } from "undici";

const URL = "https://www.foo.com";

async function main() {
  const mockAgent = new MockAgent({ connections: 1 });
  mockAgent.disableNetConnect();
  const mockPool = mockAgent.get(URL);
  mockPool.intercept({ method: "GET", path: "/foo" }).reply(400).persist();

  const client = new Pool(URL, { factory: () => mockPool });
  try {
    const response = await client
      .compose(interceptors.responseError({ throwOnError: true }))
      .request({
        method: "GET",
        path: "/foo",
      });

    console.log(response.statusCode);
  } catch (e) {
    console.log(e);
  }
}

if (require.main === module) {
  void main();
}

Expected Behavior

The expected behavior is that an exception is raised, however this does not occur (it prints undefined as statusCode).

Environment

  • node: 20.18
  • undici: 7.1.0
@Gigioliva Gigioliva added the bug Something isn't working label Dec 7, 2024
@Gigioliva
Copy link
Contributor Author

This is due to an undefined error here

@Gigioliva
Copy link
Contributor Author

#3931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant