Skip to content
Source
Sign inSign up
TanStack/router

`notFound` in parameter parser returns 500, not 404 #5733

Send to my agent
Closedmatt-thomson(GitHub profile, opens in a new tab) opened this issue 3 comments

Which project does this relate to?

Router

Describe the bug

I have a parse function for path parameters, which throws a notFound error when the parameters aren't in the required format. For example:

export const Route = createFileRoute('/$id')({
  component: Home,
  params: {
    parse: ({ id }) => {
      const parsedId = parseInt(id, 10);

      if (Number.isNaN(parsedId)) {
        throw notFound();
      }

      return { id: parsedId };
    }
  },
  notFoundComponent: () => <div>Page not found</div>
})

However, this leads to a 500 error, not the 404 that I'd expect. Is this the correct behaviour or a bug? If it's expected, is there a way to get the 404 in this case?

See full example in this repository. I asked about this in the Discord here and was recommended to create this issue.

Your Example Website or App

https://github.com/matt-thomson/tanstack-validate-not-found/

Steps to Reproduce the Bug or Issue

See above

Expected behavior

I expect to see a 404 error, but instead I get a 500.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.134.9
  • OS: Linux
  • Browser: Firefox
  • Browser Version: 144.0.2
  • Bundler: vite
  • Bundler Version: 7.1.7

Additional context

No response

  1. @matt-thomson , this should be resolved in the release that comes out in a minute. Let us know if it's working as expected.

  2. @matt-thomson @birkskyum

    After checking the repo he provided, it appears the issue has been resolved.

    Image Image
  3. Yep this is working for me, thanks for the fix!

Sign in to join this conversation.