Skip to content

Instantly share code, notes, and snippets.

@timothycrosley
Last active April 1, 2016 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothycrosley/e859291db3d160e104ac to your computer and use it in GitHub Desktop.
Save timothycrosley/e859291db3d160e104ac to your computer and use it in GitHub Desktop.
Custom Exception handling
import hug
from project import exceptions
@hug.exception((exceptions.CustomExceptionTypeOne, exceptions.CustomExceptionTypeTwo))
def handle_custom_exceptions(exception):
# handles the passed in custom exception, able to return a different response here:
return {'error': 'No error here!'}
@hug.exception(Exception)
def handle_exception(exception):
return {'error': "Python broke again! Don't blame us!"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment