On Thu, Jun 23, 2011 at 2:19 PM, Steven L Smith <ssmit...@zimbra.naz.edu> wrote: > Some of our apps have to talk to databases outside of our control, and their > operators don't have the same uptime standards that we do... > > What can I do to make Django return a "503 Service Unavailable" instead of a > "500 Internal Server Error", when it encounters a DatabaseError or > ProgrammingError while trying to access the database? Bonus points if I could > make the 503 page say "there was a temporary database communication problem." > > I have some ideas of what I *could* modify, but I'd rather incorporate this > into a product or setting instead of having to patch the actual django > database backend code itself. >
Exception handling is performed by middleware. When a django view encounters an un-handled exception, each installed middleware class is asked if it wants to handle this exception. If none do, Django sends out it's pre-canned response as it sees fit. So, simply write your own exception handling middleware that handles DatabaseError or ProgrammingError, and passes on other errors. See the docs for more details: https://docs.djangoproject.com/en/1.3/topics/http/middleware/#process-exception Cheers Tom -- 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.