25 lines
787 B
Python
25 lines
787 B
Python
from werkzeug.exceptions import HTTPException
|
|
from flask import jsonify
|
|
from app.api.helpers.response_helper import ResponseHelper
|
|
|
|
def register_error_handlers(app):
|
|
@app.errorhandler(HTTPException)
|
|
def handle_http_exception(e):
|
|
return jsonify({'error': e.description}), e.code
|
|
|
|
@app.errorhandler(405)
|
|
def method_not_allowed(error):
|
|
return jsonify({"message": "Method Not Allowed"}), 405
|
|
|
|
@app.errorhandler(404)
|
|
def not_found(error):
|
|
return jsonify({"message": "Resource not found"}), 404
|
|
|
|
@app.errorhandler(400)
|
|
def bad_request(error):
|
|
return jsonify({"message": "Bad Request"}), 400
|
|
|
|
@app.errorhandler(415)
|
|
def unsupported_media_type(error):
|
|
return jsonify({"message": "Unsupported Media Type"}), 415
|