Django middleware for unhandled AJAX errors
Project description
Simple Django middleware that makes it easy to view Django’s technical error page for failed AJAX requests by automagically opening them in a different browser window.
The Problem
I reckon most if not all Django developers know about Django’s useful debug-mode unhandled error page. However, when an AJAX request reaches a faulty view, the error page will not be rendered in your browser but instead be received by your AJAX error handler (assuming you even had one), which is almost always not what you want. This forces you you to find some other way to reach your traceback information. For example, before I wrote this package, I used to regularly open Chrome’s developer tools, find the failed resource in the Resources tab, and then either read through the raw HTML (yuck) or copy and paste it to a file and double click it (tedious).
Suggested Solution
Since the problem is really about ease of development, and since I (and I suspect many other Django developers) do most of my development work locally, I figured the solution can take advantage of the server being a full fledged desktop with a modern browser and a GUI. Enter ajaxerrors.middleware.ShowAJAXErrors. This little middleware intercepts all unhandled view exceptions, pickles the technical error page and uses Python’s webbrowser module to direct a new browser tab at a special URL that will serve (and delete) the previously stored page.
All this is only triggered if DEBUG is true and request.is_ajax() is true, so pretty much everything you’re used to in your development flow should stay the same. Sweet.
Installation Instructions
- Install like any other Python package with easy_install or pip, or simply with:
python setup.py install
Add ajaxerrors.middleware.ShowAJAXErrors to your MIDDLEWARE_CLASSES setting.
You can also find more info in the package’s readme file.
Contributing
django-ajaxerrors is licensed under the MIT license, see the LICENSE file in this distribution if you’re really interested in reading all them small letters.
I’d really like to see this as a feature in Django some day, but first we should see if other people are interested and maybe add more stuff to this really simple utility. Anyway, feel free fork away and send me pull requests. I’ll do my sane best to fix any bugs for as long as… well, at least until I lose interest.
If you’d like to discuss something about django-ajaxerrors or if you are otherwise curious about me, please find me at yaniv at aknin dot name, visit django-ajaxerrors’ GitHub page or my smashing Python-centric tech blog.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.