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).
fullstack ruleP1universalStack: JavaScript
autherror-handlingguard-clauseux
Don't issue a request you know will fail without auth
If a call requires a session that is absent, short-circuit with a clear error rather than firing a request that returns nothing and surfaces a confusing empty state.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const session = readCookie('session'); |
| 2 | const res = await fetch(url, { headers: { session } }); // returns empty if no session |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const session = readCookie('session'); |
| 2 | if (!session) { |
| 3 | return { data: [], error: 'Please sign in to see this' }; |
| 4 | } |
| 5 | const res = await fetch(url, { headers: { session } }); |
Explanation (EN)
Objašnjenje (HR)