diff --git a/app/api/blueprint.py b/app/api/blueprint.py index 0b005ca..7a6d10e 100644 --- a/app/api/blueprint.py +++ b/app/api/blueprint.py @@ -1,6 +1,6 @@ from flask_restful import Api from marshmallow import ValidationError -from app.errors import NotPresentError +from app.errors import NotPresentError, BadRequestError from flask import Blueprint, jsonify @@ -96,6 +96,12 @@ def handle_not_present_error(e): return jsonify({'status': 'error', 'message': str(e)}), 404 +@api_bp.errorhandler(BadRequestError) +@api_bp.errorhandler(400) +def handle_bad_request_error(e): + return jsonify({'status': 'error', 'message': str(e)}), 400 + + @api_bp.errorhandler(Exception) @api_bp.errorhandler(500) def handle_unknown_errors(e): diff --git a/app/errors.py b/app/errors.py index df97152..af3f572 100644 --- a/app/errors.py +++ b/app/errors.py @@ -1,5 +1,6 @@ class NotPresentError(Exception): pass + class BadRequestError(Exception): pass