|
1 | 1 | # Standard |
2 | 2 | from argparse import Namespace |
| 3 | +from http import HTTPStatus |
3 | 4 | import inspect |
4 | 5 | import signal |
5 | 6 |
|
|
14 | 15 | from vllm.entrypoints.logger import RequestLogger |
15 | 16 | from vllm.entrypoints.openai import api_server |
16 | 17 | from vllm.entrypoints.openai.cli_args import make_arg_parser, validate_parsed_serve_args |
17 | | -from vllm.entrypoints.openai.protocol import ErrorResponse |
| 18 | +from vllm.entrypoints.openai.protocol import ErrorInfo, ErrorResponse |
18 | 19 | from vllm.entrypoints.openai.serving_models import BaseModelPath, OpenAIServingModels |
19 | 20 | from vllm.entrypoints.openai.tool_parsers import ToolParserManager |
20 | 21 | from vllm.utils import FlexibleArgumentParser, is_valid_ipv6_address, set_ulimit |
@@ -173,8 +174,26 @@ async def validation_exception_handler( |
173 | 174 | return JSONResponse( |
174 | 175 | status_code=exc.error.code, content=exc.error.model_dump() |
175 | 176 | ) |
176 | | - # For other routes, let FastAPI handle normally |
177 | | - raise exc |
| 177 | + else: |
| 178 | + # vLLM general request validation error handling |
| 179 | + exc_str = str(exc) |
| 180 | + errors_str = str(exc.errors()) |
| 181 | + |
| 182 | + if exc.errors() and errors_str and errors_str != exc_str: |
| 183 | + message = f"{exc_str} {errors_str}" |
| 184 | + else: |
| 185 | + message = exc_str |
| 186 | + |
| 187 | + err = ErrorResponse( |
| 188 | + error=ErrorInfo( |
| 189 | + message=message, |
| 190 | + type=HTTPStatus.BAD_REQUEST.phrase, |
| 191 | + code=HTTPStatus.BAD_REQUEST, |
| 192 | + ) |
| 193 | + ) |
| 194 | + return JSONResponse( |
| 195 | + err.model_dump(), status_code=HTTPStatus.BAD_REQUEST |
| 196 | + ) |
178 | 197 |
|
179 | 198 | # api_server.init_app_state takes vllm_config |
180 | 199 | # ref. https://github.com/vllm-project/vllm/pull/16572 |
|
0 commit comments