Handle exceptions in stored procedures

This commit is contained in:
Marcus Lindvall 2019-11-19 16:24:41 +01:00
parent 5d1b5f90ac
commit 144fdbefb1

View file

@ -131,7 +131,11 @@ class OrderHead(StoredProcedure):
# self['OrderNumber'] = pymssql.output(int)
def callproc(self):
super(OrderHead, self).callproc()
try:
super(OrderHead, self).callproc()
except pymssql.DatabaseError:
logger.error("A DatabaseException has been caught. Order could not be created..")
# If call succeeded, then order is allowed to be invoiced.
return self['o_OrderNumber'], bool(self['c_webUserName'])
@ -189,7 +193,10 @@ class OrderRow(StoredProcedure):
# self['o_AllocatedDate'] = pymssql.output(str)
def callproc(self):
super(OrderRow, self).callproc()
try:
super(OrderRow, self).callproc()
except pymssql.DatabaseError:
logger.error("A DatabaseException has been caught. Order row not created.")
return self['o_OrderRow']
@ -232,6 +239,13 @@ class PlaceOrder(StoredProcedure):
self['c_orderStatus'] = None
self['c_ProvinceCode'] = None # For US customers etc.
def callproc(self):
try:
return super(PlaceOrder, self).callproc()
except pymssql.DatabaseError:
logger.error("A DatabaseException has been caught. Order %d not updated." %
(self['c_OrderNumber']))
class NotifyInfo(StoredProcedure):
"""Mapping for the JAPP_spr_LogTrade_Get_NotifyInfo stored procedure parameters
@ -245,9 +259,14 @@ class NotifyInfo(StoredProcedure):
self['c_ForetagKod'] = 1 # Hardcoded to LK
def callproc(self):
result = super(NotifyInfo, self).callproc(resultset=True)
ret = {'email': None, 'sms': None, 'phone': None}
try:
result = super(NotifyInfo, self).callproc(resultset=True)
except pymssql.DatabaseError:
logger.error("A DatabaseException has been caught. NotifyInfo not fetched.")
return ret
if isinstance(result, list):
for r in result:
if r[1][7:].lower() in ret: