Skip to content

Instantly share code, notes, and snippets.

@Sytten
Last active May 19, 2020 00:49
Show Gist options
  • Save Sytten/a22f424d5ff0a6626bc97efbd0a1edc1 to your computer and use it in GitHub Desktop.
Save Sytten/a22f424d5ff0a6626bc97efbd0a1edc1 to your computer and use it in GitHub Desktop.
failing-revenge-error-handling
@bp.app_errorhandler(Exception)
def handle_exception(e):
if type(e) == json.JSONDecodeError:
message=f"Unexpected JSON object: {e.doc}"
elif type(e) == APIException:
message=f"APIError due to API answer: {e.response}"
else:
message=f"Unexpected error: {type(e).__name__}"
import traceback
traceback.print_stack()
return render_template("error.html", message=message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment