Next.js notFound() ends as a 500 error after an exception has been caught
The non-existent article should return 404, but the catch turns the internal notFound() into a simple application error. The notFound function interrupts rendering with special exception to the framework, which can be misused.
How to identify the source of the problem
Search for notFound() calls in tri/catch blocks and see what catch support does. In the test request, compare the HTTP status of the non-existent slug and the rendering method not-found.tsx.
Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.
Repair steps
Support base errors inside tri, and the condition of no record evaluate beyond catch and call notFound() there. Keep separate states: no entry, lack of permission and failure of the API should lead to different answers.
How to Test Solution
The non-existent address returns 404 with the correct error page, and the database failure is not hidden as no entry.
Security and restrictions
Do not return 200 with the text itself “not found” because this creates Soft 404 in SEO.