Source code for superdjango.contrib.errors.backends.model

# Imports

from django.conf import settings
from django.urls import reverse, NoReverseMatch
import logging
from superdjango.shortcuts import get_model
from .base import ErrorHandler

log = logging.getLogger(__name__)

# Exports

__all__ = (
    "Model",
)

# Classes


[docs]class Model(ErrorHandler): """Write errors to the database.""" required_settings = [ "SUPERDJANGO_ERROR_CAPTURE_MODEL_NAME", ] # def handle(self, request, exception, traceback):
[docs] def handle(self, report): """Create an error record.""" model = get_model(settings.SUPERDJANGO_ERROR_CAPTURE_MODEL_NAME, raise_exception=False) if model is None: log.error("Error capture model does not exist: %s" % settings.SUPERDJANGO_ERROR_CAPTURE_MODEL_NAME) return None instance = model.log(report) try: url = reverse("captured_error_detail", kwargs={'uuid': instance.identifier}) return {'issue_url': url} except NoReverseMatch: return None