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
httpauthstatus-codes
Use 401 for authentication/authorization failures
Return 401 when a request fails because the user is not authenticated, not a generic error status.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | if (!session) { |
| 2 | return res.status(400).json({ message: 'No session' }); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | if (!session) { |
| 2 | return res.status(401).json({ message: 'Unauthorized', status: 401 }); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)