Task #7985 (closed)
Error handling docs
|Reported by:||wmoore||Owned by:||wmoore|
Description (last modified by wmoore)
Instructions for OMERO.web developers on how to handle errors.
- Built-in handling AJAX/other
- How to return specific error
- How to configure qa POST url
- How to develop / test error handling (Turn debug off, serve static via Apache etc)
This content can be added below for now - move to trac wiki later.
OMERO.web error Handling
Django comes with some nice error handling functionality. We have customised this and
Errors are handled as follows:
- 404 Simply display a 404 message to the user
- 403 This is 'permission denied' which probably means the user needs to login to the server (E.g. session may have timed out). The page is refreshed which will redirect the user to login page.
- 500 Server error. We display a feedback form for the user to submit details of the error to our QA system - POSTs to "qa.openmicroscopy.org.uk:80". This url is configurable in settings.py.
There are various scenarios for handling errors, depending on whether you handle them yourself, or allow Django to handle them,
whether you are in Debug mode or not, and whether the http request is AJAX.
If you do not write any error handling (or if the error occurs outside a try/except block etc...
With Debug: True (during development)
Django will return an html page describing the error, with various parameters, stack trace etc.
NB: With Debug True, 500 errors will be returned as html pages by Django but these will not be rendered as html in our feedback form.
You can use developer tools on your browser (E.g. Firebug on Firefox) to see various errors and open the request in a new tab
to display the full debug info as html.
With Debug: False (in production)
Django will use it's internal error handling to produce standard 404, 500 error pages. We have customised
this behaviour to display our own error pages. The 500 error page allows you to submit the error as
feedback to our QA system. If the request is AJAX, we return the stack trace is displayed in a dialog
which also allows the error to be submitted to QA.
Custom Error handling
If you want to handle certain exceptions in particular ways
you should use appropriate try/except statements.
This is only advised for trivial errors, where you can give the user a simple message, E.g."No Objects selected, Please try again", or if the error is well understood and you can recover from the error in a reasonable way.
For 'unexpected' server errors, it is best to allow the exception to be handled by Django since this will provide a lot more info to the user (request details etc)
and format html etc (both with Debug True or False).
If you still want to handle the exception yourself, you can provide stack trace alongside a message for the user. If the request is ajax, don't return html, since the response text will be displayed in a dialog box for the user (not rendered as html).
try: # something bad happens except: logger.error(traceback.format_exc()) # log the stack trace err_msg = "Something bad happened! \n \n%s" % traceback.format_exc() # message AND stack trace if request.is_ajax(): return HttpResponseServerError(err_msg) else: ... # render err_msg with a custom template return HttpResponseServerError(content)
For unknown IDs (Object not found) try to return that message in the 404 message.
Change History (7)
comment:5 Changed 8 years ago by wmoore
- Remaining Time changed from 0.4 to 0
- Resolution set to fixed
- Status changed from accepted to closed