Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep fetch error handling inside the method that owns the fetch
Centralize transport error classification without hiding domain failures.
Bad example
| 1 | async getTickersLogos() { |
| 2 | try { const raw = await this.fetchData(); /* ...mapping... */ } |
| 3 | catch (e) { /* fetch error handled far from the fetch */ } |
| 4 | } |
Explanation (EN)
A broad caller catch can blur network failure and mapping defects.
Objašnjenje (HR)
Good example
| 1 | async function fetchData(url: string): Promise<unknown> { |
| 2 | const response = await fetch(url); |
| 3 | if (!response.ok) throw new Error(`Upstream status ${response.status}`); |
| 4 | return response.json(); |
| 5 | } |
Explanation (EN)
The fetch layer checks status and propagates failures; the caller validates the data and chooses recovery.
Objašnjenje (HR)
Notes (EN)
Place transport decoding and error classification in the fetch layer when reused, while letting callers own domain recovery and user state.
Exceptions / Tradeoffs (EN)
Do not swallow all failures into null just to shorten the caller. Return a typed result or propagate errors according to the established API.