Re: [flask] Exception Handling & MySQL Connections
- Kevin Houlihan
- 2014-04-08 @ 10:21
Unhandled exceptions should already be being dealt with by the Api class,
so one option might be to subclass that and override the error handler:
from flask.ext.restful import Api as BaseApi
def handle_error(self, e):
response = super(Api, self).handle_error(e)
# Do your stuff.
On 7 April 2014 20:11, Michael Montero <firstname.lastname@example.org> wrote:
> Hi all! Hoping I can get some help on this issue. Occasionally I see
> this in my uWSGI log file:
> raise errors.OperationalError("MySQL Connection not available.")
> I suspect this is happening because fatal errors are occurring that aren't
> properly shutting down the MySQL connection - closing the open cursor and
> closing the connection.
> I'm using Flask-Restful and wondering how I might create a handler that is
> called if ANY uncaught exception is thrown so that I can shutdown the
> connection properly and re-throw the exception.
> I'm using python3, mysql-connector and Flask/Flask-Restful.
> Any ideas would be greatly appreciated.