Hello,
I’ve implemented a simplified ExceptionReporter
for sending error reports to email. I’ve overridden the get_traceback_data
method to change the context included in the email templates. I would like to include the website domain in the error report (e.g., to distinguish between staging and production environments).
I was thinking of using the Sites framework (which I have installed) and adding the current site to the traceback data, so I could then get the domain from the site object. Here’s what I’m thinking:
def get_traceback_data(self):
data = {
'is_email': self.is_email,
'request': self.request,
'site': get_current_site(self.request),
'server_time': timezone.now(),
}
if self.exc_type:
data['exception_type'] = self.exc_type.__name__
return data
However, I am unsure if calling get_current_site
could raise an exception in some situations. For obvious reasons, I don’t want my exception reporter to raise an unhandled exception
Another idea I had, was to use request.get_host
to get the domain.
Thank you!