#89 Send ProviderException with the correct error code and message
Merged 8 years ago by puiterwijk. Opened 8 years ago by puiterwijk.
puiterwijk/ipsilon exceptions-correct-code  into  master

file modified
+3 -4
@@ -10,15 +10,14 @@ 

  import cherrypy

  

  

- class ProviderException(Exception, Log):

+ class ProviderException(cherrypy.HTTPError, Log):

      code = 500

      message = None

  

      def __init__(self, message, code=None):

-         super(ProviderException, self).__init__(message)

+         super(ProviderException, self).__init__(code or self.code,

+                                                 self.message)

          self.message = message

-         if code:

-             self.code = code

          self.debug('%s [%s]' % (self.message, self.code))

  

      def __str__(self):

This makes a ProviderException(400, ..) actually send a 400 status code,
and display the correct message.
Otherwise, we were sending an error 500, because cherrypy did not
know how to interpret Exception's rather than cherrypy.HTTPError.

Signed-off-by: Patrick Uiterwijk puiterwijk@redhat.com

rebased

8 years ago

rebased

8 years ago

rebased

8 years ago

Seems a little odd to me that you override self.code.
I would have expected more something along the lines of:
super(ProviderException, self).__init__(code or self.code, self.message)

Or (above in the code):

if not code:
    code = self.code

rebased

8 years ago

Cool, :thumbsup: for me

rebased

8 years ago

Pull-Request has been merged by puiterwijk

8 years ago
Metadata