The documentation states that
Litestar handles all errors by default by transforming them into JSON responses.
Since #2131 this is not entirely true as exceptions will retain the MediaType
of the route handler.
Consider the following endpoint:
@get(sync_to_thread=False)
def handler(q: int) -> str:
raise ValueError
The MediaType
of this handler will be MediaType.TEXT
by default.
When let's say a ValidationException
is raised due to wrong/missing query param or an internal error is raised, etc. the resulting response will be a JSON error message but in the response the content-type
header will be set to text/plain
.
If a client expects JSON on errors --by for example checking the status code-- as declared in the documentation, then JSON parsing might fail as the response content-type
header does not indicate JSON.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too