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-handlingexceptionsasynccontrollers
Let unexpected errors bubble up to the framework's exception handler instead of catching to rethrow
Only catch an error when you can genuinely handle or enrich it; otherwise let it propagate to the framework's central error handler rather than catching it just to rethrow.
PR: hegnar-investor-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | async seed(): Promise<void> { |
| 2 | try { |
| 3 | await this.service.run(); |
| 4 | } catch (err) { |
| 5 | this.logger.error('failed', err); |
| 6 | throw err; // caught only to rethrow the same error |
| 7 | } |
| 8 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | async seed(): Promise<void> { |
| 2 | // Nothing here is recoverable, so let it propagate to the |
| 3 | // global exception filter, which maps it to a 500. |
| 4 | await this.service.run(); |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)