~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

Handle HTTPErrors nicely in the new framework. Currently there is no facility
to override the style of the output, however.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
from ivle.dispatch.request import Request
47
47
from ivle.dispatch import login
48
48
from ivle.webapp.base.plugins import ViewPlugin
 
49
from ivle.webapp.errors import HTTPError
49
50
import apps
50
51
import html
51
52
 
154
155
        # Instantiate the view, which should be a BaseView class
155
156
        view = viewcls(req, **kwargs)
156
157
        # Render the output
157
 
        view.render(req)
158
 
        req.store.commit()
159
 
        return req.OK
 
158
        try:
 
159
            view.render(req)
 
160
        except HTTPError, e:
 
161
            # A view explicitly raised an HTTP error. Respect it.
 
162
            req.status = e.code
 
163
            req.write(e.message)
 
164
            return e.code
 
165
        except Exception, e:
 
166
            # A non-HTTPError appeared. We have an unknown exception. Panic.
 
167
            handle_unknown_exception(req, *sys.exc_info())
 
168
        else:
 
169
            req.store.commit()
 
170
            return req.OK
160
171
    ### END New plugins framework ###
161
172
 
162
173
    # Check req.app to see if it is valid. 404 if not.