Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Identify aborted requests by error type
Recognize cancellation by the API's actual error/reason contract; do not assume all aborts are DOMException AbortError or suppress unrelated failures.
Bad example
| 1 | useEffect(() => { |
| 2 | const controller = new AbortController(); |
| 3 | const { signal } = controller; |
| 4 |
|
| 5 | fetch('/api/data', { signal }) |
| 6 | .then(res => res.json()) |
| 7 | .catch(err => { |
| 8 | // Unreliable: checks signal state instead of error type |
| 9 | if (!signal.aborted) { |
| 10 | console.error(err); |
| 11 | setError(true); |
| 12 | } |
| 13 | }); |
| 14 |
|
| 15 | return () => controller.abort(); |
| 16 | }, []); |
Explanation (EN)
Ignoring every error after a signal happens to abort can hide a real failure.
Objašnjenje (HR)
Ignoriranje svake pogreške nakon što je signal otkazan može sakriti stvarni kvar.
Good example
| 1 | try { |
| 2 | await fetch(url, { signal }); |
| 3 | } catch (error) { |
| 4 | if (signal.aborted && error === signal.reason) return; |
| 5 | throw error; |
| 6 | } |
Explanation (EN)
For native fetch with a matching abort reason, cancellation is identified without swallowing unrelated errors; adapt this check for clients with wrapped cancellation errors.
Objašnjenje (HR)
Za nativni fetch s odgovarajućim razlogom prekida otkazivanje se razlikuje od drugih pogrešaka. Klijenti koji omataju pogreške zahtijevaju prilagođenu provjeru.
Notes (EN)
Classify cancellation using the actual API's rejection contract: it may reject with AbortError, TimeoutError, a custom signal.reason or a library-specific cancellation type.
Bilješke (HR)
Otkazivanje prepoznaj prema stvarnom ugovoru API-ja: odbijanje može biti AbortError, TimeoutError, prilagođeni signal.reason ili tip konkretne biblioteke.
Exceptions / Tradeoffs (EN)
signal.aborted alone does not prove an unrelated error was caused by cancellation. A signal guard remains useful before committing results after a lifecycle ends.