Skip to content

Throw when the path is undefined in res.redirect. #6391

@bjohansebas

Description

@bjohansebas
Member

I think it would make sense to throw an error when the path is undefined in res.redirect. The current behavior redirects to /undefined, which I wouldn't consider very intuitive.

This functionality would be a breaking change, so it could be a candidate for Express 6. What do you all think?

Activity

banskotanup

banskotanup commented on Mar 16, 2025

@banskotanup

I think throwing an error will be great whenever path is undefined in res.redirect.

baltej223

baltej223 commented on Mar 16, 2025

@baltej223

Yep, it's pretty intuitive to throw an error rather than redirect to /undefined

dpopp07

dpopp07 commented on Mar 17, 2025

@dpopp07
Contributor

The current behavior redirects to /undefined, which I wouldn't consider very intuitive.

Agreed - that sounds like the kind of sneaky, unexpected behavior that is hard to debug. The path is also documented as required so an error would make sense (as a side note, I find it odd that the optional argument comes first for this method - that's not a great practice and most of the other methods don't do that).

bjohansebas

bjohansebas commented on Mar 17, 2025

@bjohansebas
MemberAuthor

(as a side note, I find it odd that the optional argument comes first for this method - that's not a great practice and most of the other methods don't do that)

Interesting that this was deprecated in v4 and removed in v5 (See #2941), it probably should never have been that way. I also find it just as strange that the optional argument is the first one.

wesleytodd

wesleytodd commented on Apr 11, 2025

@wesleytodd
Member

Agreed on all of this. Let's keep that 6.x label on here, and when we start the branch we can open a PR for it.

wesleytodd

wesleytodd commented on Apr 11, 2025

@wesleytodd
Member

Oh! Ha, already done just no branch to make it against. We can close this then and just re-target that when we are ready.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @wesleytodd@dpopp07@baltej223@banskotanup@bjohansebas

      Issue actions

        Throw when the path is undefined in res.redirect. · Issue #6391 · expressjs/express