From 49f9e96b4048ef5a069c5038d649b2553799f961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Sat, 3 Nov 2018 18:32:35 +0100 Subject: [PATCH] Add handler for bad request error --- app/api/blueprint.py | 8 +++++++- app/errors.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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