Skip to main content

Generic handler for hooking client side javascript error.

Project description

To run the demo project for testing:

$ git clone git://github.com/jojax/django-js-error-hook.git
$ cd django-js-error-hook
$ virtualenv env --python=python3
$ source env/bin/activate
(env) $ pip install -e .
(env) $ pip install -e demo
(env) $ demo migrate

Run the server:

(env) $ demo runserver

Then access: http://localhost:8000/ - the JavaScript error will be logged in your console.

To install the project in production:

$ pip install django-js-error-hook

Add django-js-error-hook to your INSTALLED_APPS settings:

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles',
    'django_js_error_hook',
    ...
)

If you want to log the error in the console for development:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '\033[22;32m%(levelname)s\033[0;0m %(message)s'
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
            },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'javascript_error': {
            'handlers': ['mail_admins', 'console'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

By default the logger is called “javascript_error”, if you want you can define JAVASCRIPT_ERROR_ID in your settings:

JAVASCRIPT_ERROR_ID = '<your logger name>'

The view will do csrf validation - if for some reason it doesn’t work, set JAVASCRIPT_ERROR_CSRF_EXEMPT to True in your settings.

Then install the urls:

urlpatterns = patterns('',
    ...
    url(r'^js_error_hook/', include('django_js_error_hook.urls')),
    ...
)

In your template, simply add the js_error_hook script:

<script type="text/javascript" src="{% url 'js-error-handler-js' %}"></script>

Now every JavaScript error will be logged in your logging error stream. (Mail, Sentry, …)

Have fun and feel free to fork us and give us feedbacks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-js-error-hook-0.7.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

django_js_error_hook-0.7-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file django-js-error-hook-0.7.tar.gz.

File metadata

  • Download URL: django-js-error-hook-0.7.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.7

File hashes

Hashes for django-js-error-hook-0.7.tar.gz
Algorithm Hash digest
SHA256 2ee2d0d5b2a17012599d3457881855a32a94109364e132f6f87e126113343d5b
MD5 0d964d984e058bc0804c46338eea5974
BLAKE2b-256 0e8994e45cef15738bc0ef6831c750af9ba7276da625a274f68d894f58bdffdb

See more details on using hashes here.

File details

Details for the file django_js_error_hook-0.7-py3-none-any.whl.

File metadata

  • Download URL: django_js_error_hook-0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.7

File hashes

Hashes for django_js_error_hook-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 863f05031ea47d634a281136c768b5217c0c7562b71c90df8f8b116820071168
MD5 1771ff7574630e3045eab771bfaba8f8
BLAKE2b-256 4e27d04fd279fc67e60eb341a9101406cf154286b91f86a142f52717a97368c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page