chula.www.controller.error – Error controller

class chula.www.controller.error.Error(env, config)

Default error controller.

_crappy_static_server(path)

Fetch a static file from disk, changing headers and HTTP status as appropriate.

Parameters:path (chula.www.adapters.env.BaseEnv.REQUEST_URI) – Path relative
Return type:str
e404()

Controller method to serve chula.www.http.HTTP_NOT_FOUND requests.

e404_render()

Method to render the 404. The intended use of this method is for an application to have an error controller that overloads this method. This way applications can share the [somewhat crazy] logic of serving static resources (css, js), but still have a custom 404 page (if the web server isn’t doing this).

Here’s an example error controller that might do this:

>>> from chula.www.controller import error
>>>
>>> class Error(error.Error):
...     def e404_render(self):
...         return self.render('/view/e404.tmpl')
>>>
e500()

Controller method to serve chula.www.http.HTTP_INTERNAL_SERVER_ERROR requests.

This method will add an exception key to the controller’s self.model with the following attributes:

summary

Summery information about the exception, of type str

message

Detailed description of the exception, of type str

traceback

Traceback, of type list

Note

This method creates the above structure and then returns e500_render(). You should overload that method if you want to render the exception detail differently.

e500_render(model)

Method to render the traceback as html. The intended use of this method is for an application to have an error controller that overloads this method. This way applications can share the [somewhat crazy] logic of capturing a useful traceback, but render it uniquely to each application if it so desires.

Here’s an example error controller that might do this:

>>> from chula.www.controller import error
>>>
>>> class Error(error.Error):
...     def e500_render(self):
...         return self.render('/view/error.tmpl')
>>>

Where the controller’s render() method would use a Mako mako.template.Template or something to render the model.

With this type of implementation, the Mako template referenced above (webapp/view/error.tmpl) might look like:

% if not model.exception is None:
  <br/>
  <div class="exception">
    <fieldset>
      <legend>Application Error</legend>
      <h1>Summary</h1>
      ${model.exception['summary']}

      <h1>Message</h1>
      ${model.exception['message']}

      <h1>Traceback</h1>
      <ol>
        % for part in model.exception['traceback']:
          <li>${part | h}</li>
        % endfor
      </ol>
    </fieldset>
  </div>
% endif

Previous topic

chula.www.controller.base – Base controller

Next topic

chula.www.http – HTTP status codes

This Page