Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Created August 7, 2014 09:57
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 brendanmckenzie/a9ac2d889e122541a67f to your computer and use it in GitHub Desktop.
Save brendanmckenzie/a9ac2d889e122541a67f to your computer and use it in GitHub Desktop.
def init_errors(app):
messages = {
400: 'Bad request.',
401: 'Unauthorised.',
403: 'Forbidden.',
404: 'Not found.',
405: 'Method not allowed.',
406: 'Not acceptable.',
500: 'Server error.'
}
@app.errorhandler(400)
def error_400(err):
return messages[400], 400, {'Content-Type': 'text/plain'}
@app.errorhandler(401)
def error_401(err):
return messages[401], 401, {'Content-Type': 'text/plain'}
@app.errorhandler(403)
def error_403(err):
return messages[403], 403, {'Content-Type': 'text/plain'}
@app.errorhandler(404)
def error_404(err):
return messages[404], 404, {'Content-Type': 'text/plain'}
@app.errorhandler(405)
def error_405(err):
return messages[405], 405, {'Content-Type': 'text/plain'}
@app.errorhandler(406)
def error_406(err):
return messages[406], 406, {'Content-Type': 'text/plain'}
@app.errorhandler(500)
def error_500(err):
app.logger.error(err)
return messages[500], 500, {'Content-Type': 'text/plain'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment