[t-018] Create exceptions.py — Complete global exception handlers #18

Open
opened 2026-07-05 08:31:01 +00:00 by david · 0 comments
Owner

Goal

Implement comprehensive error handling for all documented error codes from DOMAIN.md §10.

References

Reference

  • AGENT.md §10 Security Constraints (Error codes table)
  • DESIGN.md §4 BFF models (exceptions.py)

Implementation Steps

Implementation Steps

1. Replace placeholder in src/core/exceptions.py with full module:

# src/core/exceptions.py
from fastapi import Request, HTTPException
from fastapi.responses import JSONResponse

def handle_http_exception(request: Request, exc: HTTPException) -> JSONResponse:
    return JSONResponse(
        status_code=exc.status_code,
        content={"error": exc.detail},
    )

# Map specific error codes to HTTP statuses
ERROR_CODE_MAP = {
    "auth_invalid": 401,
    "session_not_found": 404,
    "file_too_large": 413,
    "unsupported_file_type": 415,
    "hermes_unreachable": 502,
    "hermes_error": 502,
    "workspace_out_of_bounds": 403,
    "rate_limited": 429,
}

def error_response(code: str) -> HTTPException:
    status = ERROR_CODE_MAP.get(code, 500)
    return HTTPException(status_code=status, detail=code)

Verification Gate

Verification Gate

Run:

cd /home/david/Projects/keryx-bff && uv run python -c "
from src.core.exceptions import error_response, ERROR_CODE_MAP
exc = error_response('auth_invalid')
assert exc.status_code == 401
assert exc.detail == 'auth_invalid'
exc2 = error_response('workspace_out_of_bounds')
assert exc2.status_code == 403
print('OK')"
# Expected output: OK

STOP Conditions

STOP Conditions

  • If any error code in the ERROR_CODE_MAP has the wrong HTTP status, stop and fix.

Depends on: t-004

## Goal Implement comprehensive error handling for all documented error codes from DOMAIN.md §10. ## References ## Reference - AGENT.md §10 Security Constraints (Error codes table) - DESIGN.md §4 BFF models (exceptions.py) ## Implementation Steps ## Implementation Steps ### 1. Replace placeholder in `src/core/exceptions.py` with full module: ```python # src/core/exceptions.py from fastapi import Request, HTTPException from fastapi.responses import JSONResponse def handle_http_exception(request: Request, exc: HTTPException) -> JSONResponse: return JSONResponse( status_code=exc.status_code, content={"error": exc.detail}, ) # Map specific error codes to HTTP statuses ERROR_CODE_MAP = { "auth_invalid": 401, "session_not_found": 404, "file_too_large": 413, "unsupported_file_type": 415, "hermes_unreachable": 502, "hermes_error": 502, "workspace_out_of_bounds": 403, "rate_limited": 429, } def error_response(code: str) -> HTTPException: status = ERROR_CODE_MAP.get(code, 500) return HTTPException(status_code=status, detail=code) ``` ## Verification Gate ## Verification Gate Run: ```bash cd /home/david/Projects/keryx-bff && uv run python -c " from src.core.exceptions import error_response, ERROR_CODE_MAP exc = error_response('auth_invalid') assert exc.status_code == 401 assert exc.detail == 'auth_invalid' exc2 = error_response('workspace_out_of_bounds') assert exc2.status_code == 403 print('OK')" # Expected output: OK ``` ## STOP Conditions ## STOP Conditions - If any error code in the ERROR_CODE_MAP has the wrong HTTP status, stop and fix. Depends on: t-004
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/keryx-bff#18
No description provided.