[Kimchi-devel] Pay attention in Wok/Kimchi exceptions types

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Mon Feb 15 21:42:40 UTC 2016


Hi all,

today I came across a doubt that I had never thought carefully before: 
What the right exception to return in a given code situation.
I was returning "OperationFailed" instead of "InvalidParameter", when I 
received a higher value than expected during an update.
Problem is that the first returns code '500' and the other '400', which 
are different in meaning.

So, looking at the code, Wok has these return exceptions types (from 
wok/control/base.py):

              except MissingParameter, e:
                 raise cherrypy.HTTPError(400, e.message)
             except InvalidParameter, e:
                 raise cherrypy.HTTPError(400, e.message)
             except InvalidOperation, e:
                 raise cherrypy.HTTPError(400, e.message)
             except UnauthorizedError, e:
                 raise cherrypy.HTTPError(403, e.message)
             except NotFoundError, e:
                 raise cherrypy.HTTPError(404, e.message)
             except OperationFailed, e:
                 raise cherrypy.HTTPError(500, e.message)
             except WokException, e:
                 raise cherrypy.HTTPError(500, e.message)

You can have more information here: 
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

I would like to ask everybody to pay more attention in the exceptions 
you are using in your code and during the code reviews.
If you find an exception somewhere that does not make sense, feel free 
to send a patch  ;-]

PS. Thanks Aline for the help.

Regards,

Rodrigo Trujillo




More information about the Kimchi-devel mailing list