Skip to content

Instantly share code, notes, and snippets.

@lonnen
Created December 31, 2012 22:28
Show Gist options
  • Save lonnen/4423380 to your computer and use it in GitHub Desktop.
Save lonnen/4423380 to your computer and use it in GitHub Desktop.
How to implement a custom error code for use with Flask
from werkzeug.exceptions import HTTPException
class FailedDependency(HTTPException):
code = 424
description = "The request failed due to failure of a previous request."
name = "Failed Dependency"
def get_response(self, environment):
resp = super(FailedDependency, self).get_response(environment)
resp.status = "%s %s" % (self.code, self.name.upper())
return resp
# using it
import requests
def fetch_tags():
url = "https://api.github.com/repos/mozilla/socorro/git/refs/tags"
response = requests.get(url)
if response.status_code == 200:
return response.json()
raise FailedDependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment