Skip to content

Commit

Permalink
fixup! sf_base: add decorator to gracefully handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Oct 30, 2023
1 parent c0b26dc commit 96812b3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions shopfloor_base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ def catch_errors(response_error):

def _catch_errors(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
def wrapper(self, *args, **kwargs):
savepoint = self._actions_for("savepoint").new()
try:
res = fn(*args, **kwargs)
res = fn(self, *args, **kwargs)
except ValidationError as ex:
savepoint.rollback()
message = {
"message_type": "error",
"body": ex.name,
}
return response_error(*args, **kwargs, message=message)
return response_error(self, *args, **kwargs, message=message)
savepoint.release()
return res

return wrapper
Expand Down

0 comments on commit 96812b3

Please sign in to comment.