Self-hosted knowledge management for SMEs: a split-screen Markdown editor whose sections an LLM refines while you write, and RAG question answering over the documents that result. FastAPI + Postgres/pgvector on the back, SvelteKit on the front, everything OpenAI-compatible and self-hostable. Squashed into a single commit; the development history stays local. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CA43ZJda8Rbp2hKXNy8f6b
21 lines
671 B
Python
21 lines
671 B
Python
from fastapi import FastAPI, Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
|
class ApiError(Exception):
|
|
"""API error rendered as the protocol's {detail, code} problem shape."""
|
|
|
|
def __init__(self, status_code: int, detail: str, code: str) -> None:
|
|
self.status_code = status_code
|
|
self.detail = detail
|
|
self.code = code
|
|
|
|
|
|
def register_exception_handlers(app: FastAPI) -> None:
|
|
@app.exception_handler(ApiError)
|
|
async def handle_api_error(request: Request, exc: ApiError) -> JSONResponse:
|
|
return JSONResponse(
|
|
status_code=exc.status_code,
|
|
content={"detail": exc.detail, "code": exc.code},
|
|
)
|