throwOnMaxRedirects is documented, but misnamed, and not in type definitions
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
})
),
Expected Behavior
-
Documentation specifies how someone can properly trigger an exception using either
throwOnMaxRedirectorthrowOnMaxRedirects(not sure which one is correct, but personal preference isthrowOnMaxRedirects -
RedirectInterceptorOptsare updated to accept an optionalthrowOnMaxRedirects(orthrowOnMaxRedirectif that's the preference) boolean for typescript users
Logs & Screenshots
Environment
macOS Sequoia 15.5 (24F74) pnpm 10.11.0 node 24.2.0 undici 7.13.0
Additional context
Good catch! Would you like to send a PR to fix?
@Ethan-Arrowood I'll give it a shot within the next few hours 👍
I gave it a go here https://github.com/nodejs/undici/pull/4377