INNER CODE UNIT · Python

http_error_exception_handler

mfmezger/conversational-agent-langchain · src/agent/api.py:88

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(
        status_code=exc.status_code,
        message=str(exc.detail),
        error_type="invalid_request_error" if exc.status_code < 500 else "server_error",
        param=None,
        code="not_found" if exc.status_code == 404 else "http_error",
    )


@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError) -> Response:
    """Use OpenAI validation envelopes only below the compatibility prefix."""
    if not _is_openai_path(request.url.path):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…