Skip to content

Incorrect error thrown on invalid statusCode #3950

Closed

Description

@paucabuti

Bug Description

The current implementation of undici version 7.1.0 throws a ResponseError object type when a request fails with a statusCode greater than 400. However, the TypeScript types do not include a definition for ResponseError.

Additionally, there is a ResponseStatusCodeError type defined in the TypeScript types, which seems to be intended for such scenarios. This creates an inconsistency, as the code throws ResponseError while the typings suggest ResponseStatusCodeError should be used.

Reproducible By

  1. Make a request that returns a statusCode > 400.
  2. Observe that the error thrown is a ResponseError with UND_ERR_RESPONSE code , which is not part of the TypeScript definitions.

Expected Behavior

The error thrown when a request fails with statusCode > 400 should either:

  • Be updated to throw a ResponseStatusCodeError, matching the TypeScript definitions.
  • Have the missing ResponseError type reintroduced in the TypeScript definitions, if it is the intended behavior.

Activity

  1. added
    TypesChanges related to the TypeScript definitions
    on Dec 17, 2024
  2. metcoder95 commented on Dec 17, 2024

    @metcoder95
    Member

    Thanks for the report! Would you like to send a PR for that?

  3. dancastillo commented on Dec 28, 2024

    @dancastillo
    Contributor

    Looks to be solved in #3964

  4. paucabuti commented on Jan 9, 2025

    @paucabuti
    Author

    Looks to be solved in #3964

    Only partially, and not in the right direction. The ResponseError is only being used in response error interceptor. Instead of creating the type, it might be better to address the root issue, eliminate ResponseError (if it’s confirmed that it’s only used there), and move to using specific errors (such as ResponseStatusCodeError in this case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypesChanges related to the TypeScript definitionsbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions