flask-demo-api/flask_demo_api/error_handlers.py

15 lines
306 B
Python

from flask import Flask, jsonify
def not_found_error(e):
return jsonify(error=str(e)), 404
def bad_request_error(e):
return jsonify(error=str(e)), 400
def register_errors(app: Flask):
app.register_error_handler(404, not_found_error)
app.register_error_handler(400, bad_request_error)