Catching Oracle Errors

36 views
Skip to first unread message

Dan Gentry

unread,
Jul 10, 2012, 9:45:58 AM7/10/12
to django...@googlegroups.com

My Django app runs on an Oracle database.

A few times a year, the database is unavailable because of a scheduled process or unplanned downtime. However, I can't see how to catch the error and give a useful message back to the requester. Instead, a 500 error is triggered, and I get an email (or hundreds) showing the exception. One example is:

  File "/opt/UDO/env/events/lib/python2.6/site-packages/django/db/backends/oracle/base.py", line 447, in _cursor
    self
.connection = Database.connect(conn_string, **conn_params)

DatabaseError
: ORA-01035: ORACLE only available to users with RESTRICTED SESSION privilege

I see a similar error with a different ORA number when the DB is down.

Because the exception is thrown deep within the Django libraries, and can be triggered by any of my views or the built in admin views, I don't know where any exception trapping code would go.

Any suggestions?

Ian

unread,
Jul 11, 2012, 1:20:23 PM7/11/12
to django...@googlegroups.com
There's nothing specific to Oracle about this.  First, make sure you've read:

https://docs.djangoproject.com/en/1.4/howto/error-reporting/

In your case you might do any of the following:

1) Customize the 500.html server error template to provide a more user-friendly message.

2) Customize the server error view, which by default just renders the 500.html template:
https://docs.djangoproject.com/en/1.4/topics/http/views/#the-500-server-error-view

3) Use a middleware to customize completely how otherwise unhandled errors are processed.  You can create a customized 500 (or 503) response and do whatever admin notification and other processing you want.

Dan Gentry

unread,
Jul 11, 2012, 4:07:56 PM7/11/12
to django...@googlegroups.com
Thanks Ian.  I'll see what I can do.



Reply all
Reply to author
Forward
0 new messages