Files
adminandClaude Opus 4.8 b272681c37 Move the org tree + permissions and shared enums/errors into core
Node/PermissionGrant/Favorite, the effective-role resolver + grant CRUD (authz), the NodeRole/PrincipalType/ReviewPolicy/EncryptionMode enums and the AppError Problem-Details hierarchy now live in dredd-core, so the family shares one org tree + permission model. Node moves whole (incl. review_policy/encryption_mode) to stay schema-neutral. Node-tree CRUD and the FastAPI error handlers stay app-side.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-09-12 14:48:26 +02:00

44 lines
1.2 KiB
Python

"""RFC 9457 Problem Details error hierarchy — the family's shared exception types.
Pure exceptions (no web framework): each app wires these to its own handlers/middleware. `status_code`
and `title` drive the Problem Details response; `extra` carries machine-readable context (e.g. a save
conflict returns the sha it collided with)."""
from __future__ import annotations
class AppError(Exception):
status_code = 500
title = "Internal Server Error"
def __init__(self, detail: str | None = None, extra: dict | None = None):
self.detail = detail or self.title
# Extra members merged into the Problem Details body. RFC 9457 §3.2 allows this, and a client
# that has to *act* on an error needs machine-readable context.
self.extra = extra or {}
super().__init__(self.detail)
class AuthenticationError(AppError):
status_code = 401
title = "Unauthorized"
class AuthorizationError(AppError):
status_code = 403
title = "Forbidden"
class NotFoundError(AppError):
status_code = 404
title = "Not Found"
class ConflictError(AppError):
status_code = 409
title = "Conflict"
class ValidationError(AppError):
status_code = 422
title = "Unprocessable Entity"