INNER CODE UNIT · Python
openai_api_exception_handler
mfmezger/conversational-agent-langchain · src/agent/api.py:76
async def openai_api_exception_handler(_request: Request, exc: openai_compat.OpenAIAPIError) -> JSONResponse:
"""Render explicit OpenAI compatibility errors."""
return _openai_error_response(
status_code=exc.status_code,
message=exc.message,
error_type=exc.error_type,
param=exc.param,
code=exc.code,
)
@app.exception_handler(StarletteHTTPException)
async def http_error_exception_handler(request: Request, exc: StarletteHTTPException) -> Response:
"""Use OpenAI error envelopes for HTTP errors below the compatibility prefix."""
if not _is_openai_path(request.url.path):
return await http_exception_handler(request, exc)
return _openai_error_response(