Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Let services own failure detail and return a value-or-null, not transport codes
Return domain results from services and map them to HTTP at the boundary; preserve meaningful failure distinctions.
Bad example
| 1 | const r = await service.getToken(); |
| 2 | if (r.reason === 'badCountry') return res.status(500).end(); |
| 3 | if (r.reason === 'upstream') return res.status(502).end(); |
| 4 | if (r.reason === 'noData') return res.status(422).end(); |
Explanation (EN)
Arbitrary transport decisions without a defined domain mapping can misclassify failures.
Objašnjenje (HR)
Good example
| 1 | const result = await service.getToken(); |
| 2 | if (!result.ok) return sendTokenFailure(res, result.error); |
| 3 | return res.json({ token: result.token }); |
Explanation (EN)
The shared boundary mapper translates a typed domain failure according to the endpoint contract.
Objašnjenje (HR)
Notes (EN)
Keep transport status mapping in the HTTP boundary and return domain data, typed failures or meaningful exceptions from the service.
Exceptions / Tradeoffs (EN)
Do not collapse distinct service failures into null and a generic 500 when callers need different recovery. Domain result discriminants are appropriate even when the controller maps them to statuses.