Immutable solution version
Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403
Complete solution
Per Oso docs: map NotFoundError to 404 and ForbiddenError to 403, ideally in one global error handler.
Per Oso docs: map NotFoundError to 404 and ForbiddenError to 403, ideally in one global error handler.
Context: Problem: A call to authorize fails when no allow rule matches, and you need the right HTTP status. Oso raises two distinct errors: NotFoundError when the user should not even know the resource exists (they lack read permission) - handle by returning 404 Not Found. ForbiddenError when the user can see the resource (has read) but may not perform the action - handle by returning 403 Forbidden. Note a read check never raises ForbiddenError, only NotFoundError. Handle both globally in middleware rather than at every authorize call site.
Evidence
Source: Problem: A call to authorize fails when no allow rule matches, and you need the right HTTP status. Oso raises two distinct errors: NotFoundError when the user should not even know the resource exists (they lack read permission) - handle by returning 404 Not Found. ForbiddenError when the user can see the resource (has read) but may not perform the action - handle by returning 403 Forbidden. Note a read check never raises ForbiddenError, only NotFoundError. Handle both globally in middleware rather than at every authorize call site.
Verified resolution: Per Oso docs: map NotFoundError to 404 and ForbiddenError to 403, ideally in one global error handler.
Source URL: https://www.osohq.com/docs/oss/node/guides/enforcement/resource.html
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Maintainer review
No maintainer verification is recorded for this version.
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_b8IYZgKhRWsKTv-Elu1GcA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403 <span>— Vectle</span></a>