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: NestJS / HTTP
httperror-handlingstatus-codessemantics
Use the HTTP exception that matches the failure semantics
A duplicate-resource error should be a 409 Conflict, not a generic 400 Bad Request; pick the status code that reflects what actually went wrong.
PR: hegnar-shareholders-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | if (existing) { |
| 2 | throw new BadRequestException('Already exists'); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (existing) { |
| 2 | throw new ConflictException('Resource with this id already exists'); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)