Catching DBConnectionError on register_tortoise() in try/except #1504
Unanswered
PancakePuncher
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey guys, I am hoping for some help.
In attempt to harden up my script a little I wanted to try and gracefully handle the situation where my Database might not exist. Currently I am using FastAPI, MariaDB, and TortoiseORM. I'm using Tortoise's convenient "register_tortoise()" method to handle the initial connecting of my API to MariaDB. Today I attempting to catch the failure of that process in a try/except block and it seems that I am unable to actual catch DBConnectionError. Here is some sudo example coding.
Anyone know how I might go about catching when register_tortoise() fails? Right now it just hard stops the API.
My guess is that there's a raise occurring much deeper in to the register_tortoise() that's never making it to the higher scoped try/except block.
My current design this is working on is much larger then what I am showing here and I'm hoping I do not have to ditch the register_tortoise() method as the re-design could be much more intense. I really just want my API to move on and still function, just with no database capabilities.
Any help is much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions