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
error-handlinghttpcorrectness
Do not collapse all upstream error statuses into a single 4xx
Mapping every status >= 400 from an upstream call to 400 hides server (5xx) failures and assumes a message is present; branch on the status and guard against a null message.
PR: hegnar-user-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | if (response.status >= 400) { |
| 2 | throw new HttpException(response.message, HttpStatus.BAD_REQUEST); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (response.status === 404) throw new NotFoundException(); |
| 2 | if (response.status >= 500) throw new BadGatewayException('Upstream failed'); |
| 3 | if (response.status >= 400) { |
| 4 | throw new HttpException(response.message ?? 'Upstream error', response.status); |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)