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 pyramid.response import Response
|
||||||
from sqlalchemy.exc import OperationalError, IntegrityError
|
from sqlalchemy.exc import OperationalError, IntegrityError, DBAPIError
|
||||||
import transaction
|
import transaction
|
||||||
|
|
||||||
|
|
||||||
class ValidationError(Exception):
|
class ValidationError(Exception):
|
||||||
def __init__(self, message, Errors=None):
|
def __init__(self, message, Errors=None):
|
||||||
self.message = message
|
self.message = message
|
||||||
|
@ -10,6 +11,7 @@ class ValidationError(Exception):
|
||||||
|
|
||||||
# Now for your custom code...
|
# Now for your custom code...
|
||||||
self.Errors = Errors
|
self.Errors = Errors
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.message
|
return self.message
|
||||||
|
|
||||||
|
@ -18,9 +20,11 @@ def TryCatchFunction(f):
|
||||||
def _decorator(self, *args, **kwargs):
|
def _decorator(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return f(self, *args, **kwargs)
|
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()
|
transaction.abort()
|
||||||
response = Response("Failed validation: {0}".format(str(ex)))
|
response = Response("Failed validation: {0}".format(str(ex)))
|
||||||
response.status_int = 500
|
response.status_int = 500
|
||||||
return response
|
return response
|
||||||
|
|
||||||
return _decorator
|
return _decorator
|
||||||
|
|
Loading…
Reference in New Issue