feat: correct pass through of openai.APIStatusErrors
This commit is contained in:
parent
ecdd228a54
commit
90a54abc9b
1 changed files with 10 additions and 1 deletions
11
router.py
11
router.py
|
|
@ -418,7 +418,16 @@ async def enforce_router_api_key(request: Request, call_next):
|
|||
response.headers["Access-Control-Allow-Headers"] = "Authorization, Content-Type"
|
||||
response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
|
||||
return response
|
||||
|
||||
|
||||
|
||||
@app.exception_handler(openai.APIStatusError)
|
||||
async def _openai_api_status_error_handler(request: Request, exc: openai.APIStatusError):
|
||||
"""Forward upstream OpenAI-SDK status errors with their original status code and body
|
||||
instead of letting them bubble up as 500s."""
|
||||
body = exc.body if exc.body is not None else {"error": {"message": str(exc), "code": exc.status_code}}
|
||||
return JSONResponse(status_code=exc.status_code, content=body)
|
||||
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# 3. Global state: per‑endpoint per‑model active connection counters
|
||||
# -------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue