Skip to content

return HTTPException in async_db_request_handler #67

Description

@nurlybek-dev

Hello,
Problem, when exception raised in service with async_db_request_handler decorator, it return HTTPException, which FastAPI can't serialize and raised another exception

fastapi.exceptions.ResponseValidationError: 1 validation errors:
{'loc': ('response',), 'msg': 'value is not a valid dict', 'type': 'type_error.dict'}

code example:
Controller

@Get("/")
async def get_accounts(session: AsyncSession = Depends(config.get_db)):
    return await self.service.get_list(session)

Service

@async_db_request_handler
async def get_list(self, session: AsyncSession):
    query = select(Entity)

    if True:
        raise ValueError("ERROR")

    result = await session.execute(query)
    return result.scalars().all()

Maybe it should be raise HTTPException instead of return HTTPException?
code line
nest/core/decorators/database.py:82.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions