[Grok-dev] REST and custom exceptions

Uwe Hoffmann uwe.ng at family-hoffmann.de
Tue Sep 21 07:38:53 EDT 2010


Hi,
  i have lastly upgraded my grok instance to 1.1 . I had to make one
  modification to my app.py.

  Before the upgrade i had the following definition:

  class Error(grok.View):
     grok.context(Exception)
     grok.name(u"index.html")

     def update(self):
         self.response.setStatus(500)

     def render(self):
         return u"<html><h1>error</h1>%s\n</html>"%unicode(self.context)

  In case of REST calls this view wasn't used anymore.

  I *added* the following class:

  class ErrorREST(grok.View):
     grok.context(Exception)
     grok.name(u"index.html")
     grok.layer(RestLayer)

     def update(self):
         self.response.setStatus(500)

     def render(self):
         return u"<html><h1>error</h1>%s\n</html>"%unicode(self.context)

  ( with RestLayer as the following (but this was already defined in
    the old version)
   class RestLayer(grok.IRESTLayer):
     grok.restskin(u"rest")
  )

  After the addition (REST) POST requests use the ErrorREST view, PUT
  requests didn't use this view but a default zope message.

  I see that the grok configure.zcml special cases POST,GET and so on
  but not PUT .
  Any hints ?

  regards,
    Uwe Hoffmann



More information about the Grok-dev mailing list