Invalid pages on docs throw a 500 server error instead of 404 #1759

Closed
opened 2026-03-13 09:01:22 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Daspy11 on GitHub (Aug 22, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Visit any page that does not exist on the docs, for example https://www.better-auth.com/docs/asdfasdf
  2. See that the page returns a 500 error

Current vs. Expected behavior

Pages not being found should return a 404 not found HTTP exception, not a 5XX server exception - the latter is confusing. For example, if someone linked me to an outdated docs link, I would come to believe that the site was broken, not just that the page doesn't exist.

This is also confusing for AI agents - if you ask Claude to research what plugins are available on Better Auth, it will request https://www.better-auth.com/docs/plugins (a fairly reasonable guess), see that the page 500s, assume that the docs are unavailable and go looking elsewhere.

Finally, this also affects crawler behaviour - 404 indicates that the page should be de-indexed from search engines. Returning a 500 will leave stale docs pages in search engine indexes for longer than they should.

What version of Better Auth are you using?

N/A

System info

N/A

Which area(s) are affected? (Select all that apply)

Documentation

Auth config (if applicable)


Additional context

No response

Originally created by @Daspy11 on GitHub (Aug 22, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Visit any page that does not exist on the docs, for example https://www.better-auth.com/docs/asdfasdf 2. See that the page returns a 500 error ### Current vs. Expected behavior Pages not being found should return a 404 not found HTTP exception, not a 5XX server exception - the latter is confusing. For example, if someone linked me to an outdated docs link, I would come to believe that the site was broken, not just that the page doesn't exist. This is also confusing for AI agents - if you ask Claude to research what plugins are available on Better Auth, it will request https://www.better-auth.com/docs/plugins (a fairly reasonable guess), see that the page 500s, assume that the docs are unavailable and go looking elsewhere. Finally, this also affects crawler behaviour - 404 indicates that the page should be de-indexed from search engines. Returning a 500 will leave stale docs pages in search engine indexes for longer than they should. ### What version of Better Auth are you using? N/A ### System info ```bash N/A ``` ### Which area(s) are affected? (Select all that apply) Documentation ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the documentation label 2026-03-13 09:01:22 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 22, 2025):

Hi @Daspy11! I'm Dosu and I’m helping the better-auth team.

The docs site is built with Next.js and is supposed to return a 404 for missing pages using the notFound() function in the main docs route handler (source). If you’re seeing a 500 error instead, it’s likely because the content loader (source.getPage) is throwing an exception for missing pages rather than returning null/undefined. To fix this, update the loader so it always returns null/undefined for missing docs, and make sure the route handler calls notFound() in those cases. This will ensure users and bots get a proper 404 instead of a confusing server error. There’s currently no global error boundary to catch these cases, so handling it in the loader and route is the best approach.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 22, 2025): <!-- Greeting --> Hi @Daspy11! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The docs site is built with Next.js and is supposed to return a 404 for missing pages using the notFound() function in the main docs route handler ([source](https://github.com/better-auth/better-auth/blob/577cfb4ab3b16d22f36892c0e843f36abcee80c3/docs/app/docs/[[...slug]]/page.tsx)). If you’re seeing a 500 error instead, it’s likely because the content loader (source.getPage) is throwing an exception for missing pages rather than returning null/undefined. To fix this, update the loader so it always returns null/undefined for missing docs, and make sure the route handler calls notFound() in those cases. This will ensure users and bots get a proper 404 instead of a confusing server error. There’s currently no global error boundary to catch these cases, so handling it in the loader and route is the best approach. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/daa83cea-9769-4e05-9ba7-1b3d94aadbb2?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4164)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1759