Skip to content

Instantly share code, notes, and snippets.

@greedo
Created February 10, 2015 04:34
Show Gist options
  • Save greedo/d96aeb40fb475b955cf0 to your computer and use it in GitHub Desktop.
Save greedo/d96aeb40fb475b955cf0 to your computer and use it in GitHub Desktop.
APIException class
from flask import jsonify
class APIException(Exception):
""" Class for handling API Excpetions and Errors
"""
status_code = 400
def __init__(self, message, status_code=None, payload=None):
Exception.__init__(self)
self.message = message
if status_code is not None:
self.status_code = status_code
self.payload = payload
def to_dict(self):
rv = dict(self.payload or ())
rv['message'] = self.message
return rv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment