tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.64k stars 386 forks source link

[QUESTION] Return raised exception as Json response #555

Closed Master-Y0da closed 3 years ago

Master-Y0da commented 3 years ago

I have a frontend running with vue js...and backend with fastapi and tortoise. When I try this

get= await some_pydantic.from_queryset_single(Model.get(id=id))

If object not found prints this in console "tortoise.exceptions.DoesNotExist: Object does not exist"

How can I return that error as Json response ?...because it only appears on console...but frotend is getting a 500 error with no description.

long2ice commented 3 years ago

use Model.get_or_none or see https://fastapi.tiangolo.com/tutorial/handling-errors/

Master-Y0da commented 3 years ago

Thanks!!