2020-03-25 00:19:12 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-03-25 01:58:48 +01:00
|
|
|
from flask import jsonify
|
2020-03-25 00:19:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_standard_error_handler(code: int):
|
2020-03-25 01:58:48 +01:00
|
|
|
def error_handler(err):
|
|
|
|
return jsonify({"msg": err.description, "status": str(code)}), code
|
2020-03-25 00:19:12 +01:00
|
|
|
|
2020-03-25 01:58:48 +01:00
|
|
|
return error_handler
|
2020-03-25 00:19:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def register_all_error_handlers(app):
|
2020-03-25 01:58:48 +01:00
|
|
|
"""
|
|
|
|
function to register all handlers
|
|
|
|
"""
|
2020-03-25 00:19:12 +01:00
|
|
|
|
2020-03-25 01:58:48 +01:00
|
|
|
error_codes_to_override = [404, 403, 401, 405, 400, 409, 422]
|
2020-03-25 00:19:12 +01:00
|
|
|
|
2020-03-25 01:58:48 +01:00
|
|
|
for code in error_codes_to_override:
|
|
|
|
app.register_error_handler(code, get_standard_error_handler(code))
|