Reporting HTTP Errors

If you want to report 404 Not Found and other errors besides uncaught exceptions (500 Internal Server Error) to Sentry, you can write your own Django view for those status codes. For example:

Copied

# urls.py

handler404 = 'mysite.views.my_custom_page_not_found_view'

# views.py

from django.http import HttpResponseNotFound
from sentry_sdk import capture_message


def my_custom_page_not_found_view(*args, **kwargs):
    capture_message("Page not found!", level="error")

    # return any response here, e.g.:
    return HttpResponseNotFound("Not found")

The error message you send to Sentry will have the usual request data attached.

Refer to Customizing Error Views from the Django documentation for more information. You can also view our troubleshooting information.

You can edit this page on GitHub.