[Bugfix][Frontend] Return 4xx for client errors in /cohere/v2/chat (#60309)

Signed-off-by: sricursion <sricursion@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Sriraj
2026-10-07 04:55:34 +00:00
committed by GitHub
co-authored by Claude
parent aecb717f10
commit 43b4aaea3e
2 changed files with 29 additions and 22 deletions
+7 -16
View File
@@ -40,6 +40,9 @@ from starlette.middleware.base import BaseHTTPMiddleware
import vllm.envs as envs
from vllm.entrypoints.serve.engine.protocol import ErrorResponse
from vllm.entrypoints.serve.exception_handling.error_response import (
create_error_response,
)
from vllm.entrypoints.serve.exception_handling.utils import sanitize_message
from vllm.entrypoints.serve.utils.api_utils import (
load_aware_call,
@@ -138,15 +141,9 @@ if _SDK_AVAILABLE:
try:
result = await handler.create_chat_v2(request, raw_request)
except Exception as e: # noqa: BLE001 - report as 500 for parity
except Exception as e:
logger.exception("Error in /cohere/v2/chat: %s", e)
return JSONResponse(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value,
content=CohereError(
message=sanitize_message(str(e)),
id=_request_id(raw_request),
).model_dump(exclude_none=True),
)
return _error_response(create_error_response(e), raw_request)
match result:
case ErrorResponse():
@@ -194,15 +191,9 @@ if _SDK_AVAILABLE:
try:
chat_request = handler.to_chat_completion_request(request)
result = await render_handler.render_chat_request(chat_request)
except Exception as e: # noqa: BLE001 - report as 500 for parity
except Exception as e:
logger.exception("Error in /cohere/v2/chat/render: %s", e)
return JSONResponse(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value,
content=CohereError(
message=sanitize_message(str(e)),
id=_request_id(raw_request),
).model_dump(exclude_none=True),
)
return _error_response(create_error_response(e), raw_request)
if isinstance(result, ErrorResponse):
return _error_response(result, raw_request)