From a10abcdbcc882302beeaf2c0d1f4fa8d92f1d2d3 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Aug 21 2018 09:21:04 +0000 Subject: Return string representation of exception instead of e.args[0] in Flask error handlers. --- diff --git a/module_build_service/__init__.py b/module_build_service/__init__.py index 01d966d..cd5016f 100644 --- a/module_build_service/__init__.py +++ b/module_build_service/__init__.py @@ -113,43 +113,44 @@ def load_views(): @app.errorhandler(ValidationError) def validationerror_error(e): """Flask error handler for ValidationError exceptions""" - return json_error(400, 'Bad Request', e.args[0]) + return json_error(400, 'Bad Request', str(e)) @app.errorhandler(Unauthorized) def unauthorized_error(e): """Flask error handler for NotAuthorized exceptions""" - return json_error(401, 'Unauthorized', e.args[0]) + return json_error(401, 'Unauthorized', str(e)) @app.errorhandler(Forbidden) def forbidden_error(e): """Flask error handler for Forbidden exceptions""" - return json_error(403, 'Forbidden', e.args[0]) + return json_error(403, 'Forbidden', str(e)) @app.errorhandler(RuntimeError) def runtimeerror_error(e): """Flask error handler for RuntimeError exceptions""" - return json_error(500, 'Internal Server Error', e.args[0]) + log.exception("RuntimeError exception raised") + return json_error(500, 'Internal Server Error', str(e)) @app.errorhandler(UnprocessableEntity) def unprocessableentity_error(e): """Flask error handler for UnprocessableEntity exceptions""" - return json_error(422, 'Unprocessable Entity', e.args[0]) + return json_error(422, 'Unprocessable Entity', str(e)) @app.errorhandler(Conflict) def conflict_error(e): """Flask error handler for Conflict exceptions""" - return json_error(409, 'Conflict', e.args[0]) + return json_error(409, 'Conflict', str(e)) @app.errorhandler(NotFound) def notfound_error(e): """Flask error handler for Conflict exceptions""" - return json_error(404, 'Not Found', e.args[0]) + return json_error(404, 'Not Found', str(e)) init_logging(conf)