This has been on my todo list of a while now, so I thought I'd trying
to figure it out.

I -think- the proper way to go about this would be in a custom
middleware with a process_exception handler that checks to see if the
exception is an instanace of the database defined exceptions.  Looking
in django/db/__init__.py shows "DatabaseError" gets assigned according
to backend, so I assume it's safe to use as a check regardless of
database settings.

Turning off my database any playing I did a check on the exception
generated when the database was down, and it looks ok - atleast for
postgres:

from django.db import DatabaseError

isinstance(exception,DatabaseError) returned true.

So I though I could add this method to a middleware class:

def process_exception(self,request,exception):
    # In case django doesn't send use the original request
    from django.db import DatabaseError
    if isinstance(exception,DatabaseError):
        return HttpResponse("Database offline for maintenance - please
try back later")
    return None

Unfortunately, process_excpetion() never seems to get called.

Searching track shows a ticket that explains the problem. Exceptions
in middleware don't hit the middlware exception handlers.
Unfortunately one of my middlware does hit the database on each call,
so I had to modify my middlware to catch the exception and return a
response object.

http://code.djangoproject.com/ticket/6094

Other than making sure to handle any middlware DB exceptions manually
it seems to be working ok.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to