Fix: Catch DBApi error so that timeout errors don't lock up the software.
This commit is contained in:
parent
da6997afc6
commit
25a82a2027
@ -1,7 +1,8 @@
|
||||
from pyramid.response import Response
|
||||
from sqlalchemy.exc import OperationalError, IntegrityError
|
||||
from sqlalchemy.exc import OperationalError, IntegrityError, DBAPIError
|
||||
import transaction
|
||||
|
||||
|
||||
class ValidationError(Exception):
|
||||
def __init__(self, message, Errors=None):
|
||||
self.message = message
|
||||
@ -10,6 +11,7 @@ class ValidationError(Exception):
|
||||
|
||||
# Now for your custom code...
|
||||
self.Errors = Errors
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
@ -18,9 +20,11 @@ def TryCatchFunction(f):
|
||||
def _decorator(self, *args, **kwargs):
|
||||
try:
|
||||
return f(self, *args, **kwargs)
|
||||
except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError) as ex:
|
||||
except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError,
|
||||
DBAPIError) as ex:
|
||||
transaction.abort()
|
||||
response = Response("Failed validation: {0}".format(str(ex)))
|
||||
response.status_int = 500
|
||||
return response
|
||||
|
||||
return _decorator
|
||||
|
Loading…
Reference in New Issue
Block a user