Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Changes between Version 1 and Version 2 of Ticket #7985


Ignore:
Timestamp:
02/04/12 23:51:57 (12 years ago)
Author:
wmoore
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #7985 – Description

    v1 v2  
    4848you should use appropriate try/except statements. 
    4949For more info on logging, see [link] 
    50 For 500 errors, it is a good idea to always return the stack trace along with any message you want the user to see. 
    51 This allows users to inspect or submit the error for diagnosis etc.  
     50 
     51This is only advised for trivial errors, where you can give the user a simple message, E.g."No Objects selected, Please try again". 
     52 
     53For server errors, it is usually best to allow the exception to be handled by Django since this will provide a lot more info to the user (request details etc) 
     54and format html etc (both with Debug True or False).  
     55If you still want to handle the exception yourself, you can provide stack trace alongside a message for the user. 
     56 
    5257{{{ 
    5358try: 
     
    5661    logger.error(traceback.format_exc())                                    # log the stack trace 
    5762    err_msg = "Something bad happened! \n \n%s" % traceback.format_exc()    # message AND stack trace 
    58     return HttpResponseServerError(err_msg) 
     63    if request.is_ajax(): 
     64        return HttpResponseServerError(err_msg) 
     65    else: 
     66        ...   # render err_msg with a custom template 
     67        return HttpResponseServerError(content) 
    5968}}} 
    6069 
    6170 
     71An alternative is to raise the exception with your custom message, allowing Django to handle it: 
     72 
     73{{{ 
     74 
     75except Exception, x: 
     76    logger.error(traceback.format_exc())                                    # log the stack trace 
     77    err_msg = "Something bad happened! \n \n%s" % traceback.format_exc() 
     78    raise x.__class__(err_msg) 
     79}}} 
     80 
     81However, the stack trace of the Exception will originate from your raise statement, even though the message of the exception 
     82contains your original stack trace. 
     83 

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

We're Hiring!