Notice: In order to edit this ticket you need to be either: a Product Owner, The owner or the reporter of the ticket, or, in case of a Task not yet assigned, a team_member"

Task #7985 (closed)

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

Error handling docs

Reported by: wmoore Owned by: wmoore
Priority: minor Milestone: OMERO-4.4
Component: Documentation Version: n.a.
Keywords: n.a. Cc: atarkowska, cxallan
Resources: n.a. Referenced By: n.a.
References: n.a. Remaining Time: 0.0d
Sprint: 2012-02-14 (8)

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
also provided some client-side error handling in Javascript to deal with errors in AJAX requests.
This javascript can be found in the ..?...js code which should be included in all pages that require this functionality.
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 "". This url is configurable in

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.

Default behavior

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.
If the request was AJAX, and you have our javascript code on your page then the error will be handled as described (see above).
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).

    # something bad happens
    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)
        ...   # render err_msg with a custom template
        return HttpResponseServerError(content)

404 Errors

For unknown IDs (Object not found) try to return that message in the 404 message.

Change History (7)

comment:1 Changed 8 years ago by wmoore

  • Description modified (diff)

comment:2 Changed 8 years ago by wmoore

  • Description modified (diff)

comment:3 Changed 8 years ago by wmoore

  • Status changed from new to accepted

comment:4 Changed 8 years ago by wmoore

  • Description modified (diff)

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
Last edited 8 years ago by wmoore (previous) (diff)

comment:6 Changed 7 years ago by Chris Allan <callan@…>

(In [cae90fb0027a71a3d500a15294d3ca466de89d52/ome.git] on branch develop) handler500 is_ajax returns HttpResponseServerError?

Allows display of request info in AJAX response.
Started to remove error handling from some ajax calls, and to add docs on how
to handle errors. See #7985

comment:7 Changed 7 years ago by Aleksandra Tarkowska <A.Tarkowska@…>

(In [000914c96a471f6a14ee81e8ac6fddd4c505dc98/ome.git] on branch develop) handler500 is_ajax returns HttpResponseServerError?

Allows display of request info in AJAX response.
Started to remove error handling from some ajax calls, and to add docs on how
to handle errors. See #7985

Note: See TracTickets for help on using tickets. You may also have a look at Agilo extensions to the ticket.

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.260618 sec.)

We're Hiring!