from flask import jsonify from structlog import getLogger from slz_api_service.errors import Codes LOG = getLogger(__name__) def handle_generic_error(ex): """Generic error handler""" response = jsonify(ex.error) response.status_code = ex.status_code response.content_type = 'application/json' return response def handle_unchecked_exception(ex): """Blanket handle any unchecked application exceptions so they return a JSON response""" LOG.exception(ex) response = jsonify({ 'code': Codes.internal_error.value, 'description': 'The application encountered an internal error' }) response.status_code = 500 response.content_type = 'application/json' return response def handle_auth_error(ex): """Handles the error response for ``AuthError`` exceptions""" return handle_generic_error(ex) def handle_invalid_input_error(ex): """Handles the error response for ``InvalidInputError`` exceptions""" return handle_generic_error(ex) def handle_proto_binary_attribute_error(ex): """Handles the error response for ``ProtoBinaryAttributeError`` exceptions""" return handle_generic_error(ex)