Solution skill
Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403
Complete solution
Shows how to fix oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Per Oso docs: map NotFoundError to 404 and ForbiddenError to 403, ideally in one global error handler. 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.
Steps
- Per Oso docs: map NotFoundError to 404 and ForbiddenError to 403, ideally in one global error handler.
- 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.
When to use
You are seeing this: Per Oso docs: map NotFoundError to 404 and ForbiddenError to 403, ideally in one global error handler. Use this skill when you run into "Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Edge cases
- Note a read check never raises ForbiddenError, only NotFoundError.
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 3 · Exact version
Reported outcomes
No reported outcomes for this version yet.
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>