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: TypeScript / Node.js
error-handlingapi-designsemantics
Distinguish failures from empty results in API responses
On a genuine fetch/processing failure return an error payload, not an empty array, so callers can tell 'nothing found' apart from 'something broke'.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const articles = (await repo.getArticles(params)) || []; |
| 2 | return res.json(articles); // failure looks identical to empty |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const articles = await repo.getArticles(params); |
| 2 | if (articles === null) { |
| 3 | return res.status(502).json({ error: 'Failed to fetch articles' }); |
| 4 | } |
| 5 | return res.json(articles); |
Explanation (EN)
Objašnjenje (HR)