Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
d04163b3
Unverified
Commit
d04163b3
authored
Jun 23, 2025
by
Chang Su
Committed by
GitHub
Jun 23, 2025
Browse files
Fix RequestValidationError response format (#7487)
parent
7732bbe4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
python/sglang/srt/entrypoints/http_server.py
python/sglang/srt/entrypoints/http_server.py
+16
-4
No files found.
python/sglang/srt/entrypoints/http_server.py
View file @
d04163b3
...
...
@@ -52,6 +52,7 @@ from sglang.srt.entrypoints.openai.protocol import (
ChatCompletionRequest
,
CompletionRequest
,
EmbeddingRequest
,
ErrorResponse
,
ModelCard
,
ModelList
,
ScoringRequest
,
...
...
@@ -172,12 +173,23 @@ app.add_middleware(
@
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
(),
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment