summaryrefslogtreecommitdiff
path: root/docs/howto/error-reporting.txt
diff options
context:
space:
mode:
authorPavel Lysak <p.lysak@corp.mail.ru>2019-09-07 20:08:12 +0300
committerCarlton Gibson <carlton@noumenal.es>2020-01-16 15:25:49 +0100
commit13e4abf83e5129b44c771b2204809792087abda4 (patch)
tree4a1ae01aef949cde3210a62127a985258aae245b /docs/howto/error-reporting.txt
parenta5a28de89dabfa03302a5893102b6f1a7c7861a1 (diff)
Fixed #30752 -- Allowed using ExceptionReporter subclasses in error reports.
Diffstat (limited to 'docs/howto/error-reporting.txt')
-rw-r--r--docs/howto/error-reporting.txt56
1 files changed, 56 insertions, 0 deletions
diff --git a/docs/howto/error-reporting.txt b/docs/howto/error-reporting.txt
index e145897b2a..13043cf387 100644
--- a/docs/howto/error-reporting.txt
+++ b/docs/howto/error-reporting.txt
@@ -305,6 +305,62 @@ following attributes and methods:
traceback frame. Sensitive values are replaced with
:attr:`cleansed_substitute`.
+.. versionadded:: 3.1
+
+If you need to customize error reports beyond filtering you may specify a
+custom error reporter class by defining the
+:setting:`DEFAULT_EXCEPTION_REPORTER` setting::
+
+ DEFAULT_EXCEPTION_REPORTER = 'path.to.your.CustomExceptionReporter'
+
+The exception reporter is responsible for compiling the exception report data,
+and formatting it as text or HTML appropriately. (The exception reporter uses
+:setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when preparing the exception
+report data.)
+
+Your custom reporter class needs to inherit from
+:class:`django.views.debug.ExceptionReporter`.
+
+.. class:: ExceptionReporter
+
+ .. method:: get_traceback_data()
+
+ Return a dictionary containing traceback information.
+
+ This is the main extension point for customizing exception reports, for
+ example::
+
+ from django.views.debug import ExceptionReporter
+
+
+ class CustomExceptionReporter(ExceptionReporter):
+ def get_traceback_data(self):
+ data = super().get_traceback_data()
+ # ... remove/add something here ...
+ return data
+
+ .. method:: get_traceback_html()
+
+ Return HTML version of exception report.
+
+ Used for HTML version of debug 500 HTTP error page.
+
+ .. method:: get_traceback_text()
+
+ Return plain text version of exception report.
+
+ Used for plain text version of debug 500 HTTP error page and email
+ reports.
+
+As with the filter class, you may control which exception reporter class to use
+within any given view by setting the ``HttpRequest``’s
+``exception_reporter_class`` attribute::
+
+ def my_view(request):
+ if request.user.is_authenticated:
+ request.exception_reporter_class = CustomExceptionReporter()
+ ...
+
.. seealso::
You can also set up custom error reporting by writing a custom piece of