Files
litestar-machines-test/main.py
Eden Kirin c7060c7ed3 Asset items
2023-08-27 23:13:24 +02:00

29 lines
929 B
Python

from typing import Any
from litestar import Litestar, get
from litestar.contrib.repository.exceptions import (
RepositoryError as RepositoryException,
)
from litestar.openapi import OpenAPIConfig
from app.controllers import create_router
from app.lib import exceptions, sqlalchemy_plugin
from app.lib.service import ServiceError
def create_app(**kwargs: Any) -> Litestar:
return Litestar(
route_handlers=[create_router()],
openapi_config=OpenAPIConfig(title="My API", version="1.0.0"),
# dependencies={"session": provide_transaction},
plugins=[sqlalchemy_plugin.plugin],
exception_handlers={
RepositoryException: exceptions.repository_exception_to_http_response, # type: ignore[dict-item]
ServiceError: exceptions.service_exception_to_http_response, # type: ignore[dict-item]
},
debug=True,
**kwargs,
)
app = create_app()