undici icon indicating copy to clipboard operation
undici copied to clipboard

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

Open williamhaley opened this issue 6 months ago • 3 comments

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

williamhaley avatar Jul 31 '25 20:07 williamhaley

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

Ethan-Arrowood avatar Jul 31 '25 21:07 Ethan-Arrowood

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

williamhaley avatar Jul 31 '25 22:07 williamhaley

I gave it a go here https://github.com/nodejs/undici/pull/4377

williamhaley avatar Aug 01 '25 03:08 williamhaley