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 ruleP2universalStack: node
api-designhttp-statuserror-handling
Return only the HTTP statuses the client can act on
Don't invent fine-grained status codes (422, 502, ...) the consumer ignores; the client typically only distinguishes ok vs not-ok, so return 200/4xx/500 and log the rest.
PR: hegnar-web · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | if (!country) return res.status(422).json(...); |
| 2 | if (badGateway) return res.status(502).json(...); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // client only checks response.ok |
| 2 | if (!session) return res.status(401).end(); |
| 3 | if (somethingWentWrong) { |
| 4 | logger.error(detail); |
| 5 | return res.status(500).end(); |
| 6 | } |
| 7 | return res.status(200).json({ token }); |
Explanation (EN)
Objašnjenje (HR)