Skip to content

throwOnMaxRedirects is documented, but misnamed, and not in type definitions #4376

Closed

Description

@williamhaley

Bug Description

Documentation on main references a throwOnMaxRedirects field that can be set on the RedirectInterceptorOpts to throw an error if the maximum number of redirects are reached. I do not see throwOnMaxRedirects in the undici code aside from where it's mentioned in that documentation. That field seems to not be defined on the RedirectInterceptorOpts.

I do however see throwOnMaxRedirect (no trailing s) that is actually used to trigger exceptions. Just like throwOnMaxRedirects, throwOnMaxRedirect is not defined in the interceptor.d.ts type declarations/definitions for the pre-defined redirect interceptor opts.

Reproducible By

$ git clone https://github.com/nodejs/undici
$ grep -wrn 'throwOnMaxRedirects' ./undici
./undici/docs/docs/api/Dispatcher.md:965:  redirect({ maxRedirections: 3, throwOnMaxRedirects: true })
$ grep -wrn 'throwOnMaxRedirect' ./undici
./undici/test/interceptors/redirect.js:456:        throwOnMaxRedirect: true
./undici/test/redirect-request.js:416:        throwOnMaxRedirect: true
./undici/lib/handler/redirect-handler.js:95:    if (this.opts.throwOnMaxRedirect && this.history.length >= this.maxRedirections) {
  const res = await request(urlToFetch, {
    ...opts,
    dispatcher: getGlobalDispatcher().compose(
      interceptors.redirect({
        maxRedirections: 1,
        throwOnMaxRedirects: true
      })
    ),
Image

Expected Behavior

  1. Documentation specifies how someone can properly trigger an exception using either throwOnMaxRedirect or throwOnMaxRedirects (not sure which one is correct, but personal preference is throwOnMaxRedirects

  2. RedirectInterceptorOpts are updated to accept an optional throwOnMaxRedirects (or throwOnMaxRedirect if that's the preference) boolean for typescript users

Logs & Screenshots

Image Image Image

Environment

macOS Sequoia 15.5 (24F74)
pnpm 10.11.0
node 24.2.0
undici 7.13.0

Additional context

Activity

  1. Ethan-Arrowood commented on Jul 31, 2025

    @Ethan-Arrowood
    Collaborator

    Good catch! Would you like to send a PR to fix?

  2. williamhaley commented on Jul 31, 2025

    @williamhaley
    Author

    @Ethan-Arrowood I'll give it a shot within the next few hours 👍

  3. williamhaley commented on Aug 1, 2025

    @williamhaley
    Author

    I gave it a go here #4377

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions