[Pulp-list] Errors in controllers

Jay Dobies jason.dobies at redhat.com
Fri Feb 10 14:11:56 UTC 2012


I was thinking about the deep dive yesterday and I think slagle's got a 
really good idea on the changes we should make to the error serialization.

We already have a hook deep in the bowels of our web stuff to catch any 
unexpected exceptions, wrap them in our standard format, and raise them 
as 500s. That hook could look for one of a standard set of base 
exceptions (~6 I'd guess) and wrap with the appropriate status code.

The exception base classes would come out of the manager layer. 
Conceptually, it's not REST-specific for the manager layer to identify a 
distinction between "missing" and "bad data". Each manager can subclass 
those as necessary/appropriate. That keeps the manager layer 
front-end-agnostic but gives the info the REST layer needs.

So somewhere in our web layer, something like:

try:
   # any controller method
except MissingResource, e:
   serialize_404(e)
except BadData, e:
   serialize_400(e)
except DuplicateId, e:
   serialize_409(e)
except Exception, e:
   serialize_500(e)

That should remove some of the busy-work from the controllers since the 
call to the managers shouldn't need to be wrapped in any exception 
handling, they can bubble up and be handled by the web framework. We 
just need to be very careful that the managers are written using the 
right exceptions.

We'll still need access to the serialize methods for cases where it's a 
non-exception case (e.g. missing parameter from the request body), but 
that's the rare case.

-- 
Jay Dobies
Freenode: jdob @ #pulp
http://pulpproject.org | http://blog.pulpproject.org




More information about the Pulp-list mailing list