[PEAK] Sitemap driven error handling

Radek Kanovsky rk at dat.cz
Thu Jan 27 02:58:49 EST 2005


Hi,

I have slightly modified error handling in peak.web so it is now
possible to define handlers for raised exceptions via sitemap.xml
config file. Handlers are registered as views (with constant name
'handle_error') for usual content type in any location for any error
class. But only IWebExceptions are aware of location (they store actual
traversal context in local attribute). Handlers for other exceptions
have to be defined in root location. They are not found otherwise.
Usage:

    <location>

      <content type='Exception'>
        <!-- must be inside root location -->
        <view name='handle_error' function='nicelyFormatedTraceback'/>
      </content>

      <content type='web.NotFound'>
        <view name='handle_error' resource='myapp/NotFoundWithSearchForm'/>
      </content>

      <location name='secured_by_session_auth'>
        <content type='web.Unauthorized'>
          <view name='handle_error' function='redirectToLoginPage'/>
        </content>
      </location>

      <location name='secured_by_http_auth'>
        <content type='web.Unauthorized'>
          <view name='handle_error' function='send401andAuthRealm'/>
        </content>
      </location>

    </location>

This is proof of concept that works with my simple setup. It would be
better to introduce some new tag. '<content ...>' is overloaded here,
view name is constant and only one handler per exception make sense.
E.g.:

    <except type='web.Unauthorized' function='redirectToLoginPage'/>

as equivalent of:

    <content type='web.Unauthorized'>
        <view name='handle_error' function='redirectToLoginPage'/>
    </content>

I will be able to finish/polish code and send here soon.

RadekK



More information about the PEAK mailing list