Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions python/sglang/srt/entrypoints/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ChatCompletionRequest,
CompletionRequest,
EmbeddingRequest,
ErrorResponse,
ModelCard,
ModelList,
ScoringRequest,
Expand Down Expand Up @@ -172,12 +173,23 @@ async def lifespan(fast_api_app: FastAPI):
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
"""Override FastAPI's default 422 validation error with 400"""
exc_str = str(exc)
errors_str = str(exc.errors())

if errors_str and errors_str != exc_str:
message = f"{exc_str} {errors_str}"
else:
message = exc_str

err = ErrorResponse(
message=message,
type=HTTPStatus.BAD_REQUEST.phrase,
code=HTTPStatus.BAD_REQUEST.value,
)

return ORJSONResponse(
status_code=400,
content={
"detail": exc.errors(),
"body": exc.body,
},
content=err.model_dump(),
)


Expand Down
Loading