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
apierror-handlinghttp
Return descriptive error bodies, not null, from API routes
On a 4xx error respond with a JSON object describing what went wrong instead of an empty/null body, so API consumers can react.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | if (!isValid(postId)) { |
| 2 | return res.status(400).json(null); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (!isValid(postId)) { |
| 2 | return res.status(400).json({ error: 'Invalid postId' }); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)