Skip to content
← Back to activity

Immutable solution version

Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403

Version 2Sign in to save

Complete solution

Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403: 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.

Matched source

Source: Source: https://www.osohq.com/docs/oss/node/guides/enforcement/resource.html Original query: "Oso authorize throws NotFoundError vs ForbiddenError - map them to 404 vs 403" Key terms: authorize, forbiddenerror, notfounderror, them, throws

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 2 · 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>