Opened 18 years ago

Closed 16 years ago

#2481 closed defect (duplicate)

Exceptions thrown by request middleware are not caught

Reported by: Simon Willison Owned by: nobody
Component: Core (Other) Version:
Severity: minor Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


At the moment, an exception thrown by request middleware is not caught by Django's exception handling middleware, and can result in an ugly Apache default 500 error screen. This also means that you can't throw an Http404 exception in request middleware, which is annoying as an obvious use for it is to apply additional URL filtering or blocking.

My particular use case is throwing a 404 for unknown subdomains while using wildcard DNS. At the moment I'm having to use view middleware for this instead to ensure the 404 gets caught.

Is there a reason that request middleware is executed outside the main try/catch block, or could it be moved in there without breaking anything?

Here's the code in question.

Change History (3)

comment:1 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:2 by kac.gigant@…, 17 years ago

I would like to add some suggestions of mine. I think that some thing like DjangoExceptionHandler should be added it could handle all known exceptions thrown in this huge try ... except used in get_response It would be great if it could be replaced from settings by any other user class.
I think that call to mail_admins function is very annoying because it cannot be turned off. It could be one of features off DjangoExceptionHandler.
Another thing is that Http404 and PermissionDenied exceptions are not flexible. There is no way to change behavior of django when they are thrown.

comment:3 by Gary Wilson, 16 years ago

Resolution: duplicate
Status: newclosed

marking dup of #6094, as there is a patch there.

Note: See TracTickets for help on using tickets.
Back to Top