litestar-google-errors
Google JSON style error responses for Litestar OpenAPI.
litestar-google-errors is a Litestar plugin that documents HTTPException error responses in
the OpenAPI (Swagger) schema using the
Google JSON Style Guide error
format, instead of Litestar's default {"status_code", "detail", "extra"} body. It also ships
typed msgspec models to return the same error shape from your API at runtime.
Features
- Documents error responses in the OpenAPI schema using the Google JSON error format
- Covers every exception listed in a route handler's
raises=[...] - Combines exceptions that share an HTTP status code with
oneOf - Lets you configure the example
domain,locationTypeandlocation - Ships typed
msgspecmodels (GoogleErrorResponse,GoogleError,GoogleErrorItem) for runtime error bodies - Includes
py.typedfor type checkers - Supports Python 3.10+ and Litestar 2.16+
Litestar error format: before and after
Litestar's default error body:
{
"status_code": 404,
"detail": "Order not found"
}
Google JSON style error body, as documented by this plugin:
{
"error": {
"code": 404,
"message": "Order not found",
"errors": [
{
"domain": "global",
"reason": "OrderNotFound",
"message": "Order not found",
"locationType": "endpoint",
"location": "/example"
}
]
}
}
Installation
pip install litestar-google-errors
# or
uv add litestar-google-errors
Quick start
Register the plugin on your Litestar app:
from litestar import Litestar
from litestar_google_errors import GoogleErrorResponsesPlugin
app = Litestar(
route_handlers=[...],
plugins=[GoogleErrorResponsesPlugin()],
)
Every exception listed in a handler's raises=[...] appears in the OpenAPI schema in the Google
format. Exceptions that share a status code are combined with oneOf.
Configure the OpenAPI examples
GoogleErrorResponsesPlugin(domain="orders", location_type="path", example_location="/orders/1")
Return Google-style errors at runtime
The plugin only changes the OpenAPI documentation. To return the same JSON error shape from
your API, use the bundled msgspec models in a Litestar exception handler:
from litestar import MediaType, Request, Response
from litestar.exceptions import HTTPException
from litestar_google_errors import GoogleError, GoogleErrorItem, GoogleErrorResponse, LocationType
def http_exception_handler(request: Request, exc: HTTPException) -> Response[GoogleErrorResponse]:
body = GoogleErrorResponse(
error=GoogleError(
code=exc.status_code,
message=exc.detail,
errors=[
GoogleErrorItem(
domain="global",
reason=type(exc).__name__,
message=exc.detail,
locationType=LocationType.ENDPOINT,
location=request.url.path,
)
],
)
)
return Response(body, status_code=exc.status_code, media_type=MediaType.JSON)
app = Litestar(
route_handlers=[...],
plugins=[GoogleErrorResponsesPlugin()],
exception_handlers={HTTPException: http_exception_handler},
)
Limitations
Litestar has no public hook for error response schemas, so the plugin replaces the private
litestar._openapi.responses.create_error_responses function. The replacement is process-wide,
and the dependency is pinned to litestar<3 because that internal may change.
Development
uv sync
uv run pytest
uv build
License
Metadata
Release files for litestar-google-errors 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| litestar_google_errors-0.1.1.tar.gz | 48.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| litestar_google_errors-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.1 kB
Release files / litestar_google_errors-0.1.1.tar.gz
| Download URL | litestar_google_errors-0.1.1.tar.gz |
|---|---|
| Size | 48.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
191dc2656e044f966487a345979ce5f59ffb2597bf879ebf89d971d97b3e1fe1
|
|
BLAKE2b-256 checksum How to use checksums |
d6204795f8fdf14842a80cd8762e3faeba3eb9f64530194676dfc177ab5eebda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / litestar_google_errors-0.1.1-py3-none-any.whl
| Download URL | litestar_google_errors-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e797f3946820beb3992545ca173484b42f468325141148cd0f904d906187761e
|
|
BLAKE2b-256 checksum How to use checksums |
18b340de59902364fb0f2f04b917df8b48dca1a576b55b871f43d21dfe1dcbbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency log