Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
NadavTasher committed Feb 1, 2024
1 parent 61a0188 commit 617de6d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions image/src/backend/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ def wrapper(**kwargs):

# Validate all the parameters
for key, value_type in types.items():
# Convert the value using the type
kwargs[key] = value_type(kwargs.get(key))
# Fetch the value from the kwargs
value = kwargs.get(key)

try:
# Try casting into the value type
kwargs[key] = value_type(value)
except BaseException as exception:
# Re-raise type error with variable name
raise TypeError("Argument %r: %s" % (key, str(exception)))

# Get the result
result = function(**kwargs)
Expand All @@ -60,10 +67,11 @@ def wrapper(**kwargs):
except BaseException as exception:
# If debug mode is enabled, return stack
if DEBUG:
return traceback.format_exc(), 500
# Log the exception
logging.exception("Exception in %s:", rule)

# Log the exception
logging.exception("Exception in %s:", rule)
# Return the full traceback
return traceback.format_exc(), 500

# Create error response from exception
return str(exception), 500
Expand Down

0 comments on commit 617de6d

Please sign in to comment.