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: TypeScript
httpcorrectnesserror-handling
Handle non-200 success statuses, not just status !== 200 as failure
Treating any status other than 200 as an error breaks legitimate responses like 304 Not Modified; check for the actual failure range or handle 304 explicitly.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | if (response.status !== 200) { |
| 2 | throw new Error('Failed'); // 304 also throws |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (!response.ok && response.status !== 304) { |
| 2 | logger.error(`Unexpected status ${response.status}`); |
| 3 | return null; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)