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 ruleP2universalStack: TypeScript / Node.js
error-handlingseparation-of-concernsclean-code
Keep fetch error handling inside the method that owns the fetch
Push the try/catch around a network call down into the fetch method so the higher-level method stays focused on its logic.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | async getTickersLogos() { |
| 2 | try { const raw = await this.fetchData(); /* ...mapping... */ } |
| 3 | catch (e) { /* fetch error handled far from the fetch */ } |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | private async fetchData() { |
| 2 | try { return await fetch(url); } catch (e) { logger.error(e); return null; } |
| 3 | } |
| 4 | async getTickersLogos() { const raw = await this.fetchData(); /* mapping only */ } |
Explanation (EN)
Objašnjenje (HR)