Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1stack specificStack: node
next.jsssrerror-handlingcorrectness
Validate resource existence early and return 404 for missing routes
Check whether a requested resource exists in getServerSideProps/handler before running component logic, and return a real 404 instead of 200 with a null body.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | export const getServerSideProps = async ({ params }) => { |
| 2 | const data = await fetch(params.tab); // unknown tab -> 200 with null |
| 3 | return { props: { data } }; |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | export const getServerSideProps = async ({ params }) => { |
| 2 | if (!isKnownTab(params.tab)) return { notFound: true }; |
| 3 | const data = await fetch(params.tab); |
| 4 | return { props: { data } }; |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)