<commit_before>from flask import jsonify
from werkzeug.exceptions import (Unauthorized, NotFound, Conflict,
                                 PreconditionFailed, Forbidden,
                                 NotImplemented, UnsupportedMediaType,
                                 PreconditionRequired)

from .exceptions import FlumpUnprocessableEntity


def register_error_handlers(blueprint):

    @blueprint.errorhandler(Unauthorized)
    @blueprint.errorhandler(401)
    def unauthorized(e):
        return jsonify(message=str(e.description)), 401

    @blueprint.errorhandler(Forbidden)
    @blueprint.errorhandler(403)
    def forbidden(e):
        return jsonify(message=str(e.description)), 403

    @blueprint.errorhandler(NotFound)
    @blueprint.errorhandler(404)
    def page_not_found(e):
        return jsonify(message=str(e.description)), 404

    @blueprint.errorhandler(Conflict)
    @blueprint.errorhandler(409)
    def conflict(e):
        return jsonify(message=str(e.description)), 409

    @blueprint.errorhandler(PreconditionFailed)
    @blueprint.errorhandler(412)
    def precondition_failed(e):
        return jsonify(message=str(e.description)), 412

    @blueprint.errorhandler(UnsupportedMediaType)
    @blueprint.errorhandler(415)
    def unsupported_media_type(e):
        return jsonify(message='Unsupported media type'), 415<commit_msg>Add default BadRequest handler<commit_after>from flask import jsonify
from werkzeug.exceptions import (Unauthorized, NotFound, Conflict,
                                 PreconditionFailed, Forbidden,
                                 NotImplemented, UnsupportedMediaType,
                                 PreconditionRequired, BadRequest)

from .exceptions import FlumpUnprocessableEntity


def register_error_handlers(blueprint):
    @blueprint.errorhandler(BadRequest)
    @blueprint.errorhandler(400)
    def bad_request(e):
        return jsonify(message=str(e.description)), 400

    @blueprint.errorhandler(Unauthorized)
    @blueprint.errorhandler(401)
    def unauthorized(e):
        return jsonify(message=str(e.description)), 401

    @blueprint.errorhandler(Forbidden)
    @blueprint.errorhandler(403)
    def forbidden(e):
        return jsonify(message=str(e.description)), 403

    @blueprint.errorhandler(NotFound)
    @blueprint.errorhandler(404)
    def page_not_found(e):
        return jsonify(message=str(e.description)), 404

    @blueprint.errorhandler(Conflict)
    @blueprint.errorhandler(409)
    def conflict(e):
        return jsonify(message=str(e.description)), 409

    @blueprint.errorhandler(PreconditionFailed)
    @blueprint.errorhandler(412)
    def precondition_failed(e):
        return jsonify(message=str(e.description)), 412

    @blueprint.errorhandler(UnsupportedMediaType)
    @blueprint.errorhandler(415)
    def unsupported_media_type(e):
        return jsonify(message='Unsupported media type'), 415
{'fraction_non_alphanumeric': 0.09175257731958762, 'fraction_numerical': 0.026804123711340205, 'mean_word_length': 3.4307458143074583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3358859', 'n_tokens_mistral': 880, 'n_tokens_neox': 798, 'n_words': 140}