#997 Return string representation of exception instead of e.args[0] in Flask error handlers.
Merged 8 months ago by mprahl. Opened 8 months ago by jkaluza.
jkaluza/fm-orchestrator log-exceptions  into  master

@@ -113,43 +113,44 @@ 


  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))




  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))




  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))




  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))




  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))




  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))




  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))




Also log.exception in RuntimeError handler, because we generally want to know the reasons why the RuntimeError has been raised. Other exceptions are more user oriented and logging the traceback for them is in my opinion useless.

Commit 0cec1ef fixes this pull-request

Pull-Request has been merged by mprahl

8 months ago

Pull-Request has been merged by mprahl

8 months ago