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 ruleP1universalStack: node
apierror-handlinghttp-statusrest
Return a descriptive JSON body and correct status code on API errors
On an error path, send the appropriate HTTP status (e.g. 404, not a generic 500) together with a JSON message explaining why, using shared status-code constants.
PR: hegnar-forum-web · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | if (!data) return res.status(500).end(); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | if (!data) { |
| 2 | return res |
| 3 | .status(HTTP_STATUS.NOT_FOUND) |
| 4 | .json({ message: 'No data found for the given id' }); |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)