misc: send exception to sentry on views (#43116)

This commit is contained in:
Lauréline Guérin 2020-07-10 14:09:40 +02:00
parent 9740299b66
commit 7b9ec14452
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 11 additions and 6 deletions

View File

@ -19,13 +19,17 @@ import os
from threading import Lock
from contextlib import contextmanager
from django.utils import six
from django.utils.deprecation import MiddlewareMixin
from quixote import get_publisher, get_request
from quixote.errors import PublishError
from quixote.http_request import Upload
try:
import sentry_sdk
except ImportError:
sentry_sdk = None
from django.http import HttpResponse
from django.conf import settings
from django.template import loader, TemplateDoesNotExist
@ -38,6 +42,10 @@ from .publisher import WcsPublisher
from .qommon.http_request import HTTPRequest
def can_sentry():
return (sentry_sdk is not None) and (sentry_sdk.Hub.current.client is not None)
class TemplateWithFallbackView(TemplateView):
quixote_response = None
@ -54,6 +62,8 @@ class TemplateWithFallbackView(TemplateView):
context = {'body': get_publisher().finish_interrupted_request(exc)}
self.quixote_response = get_request().response
except Exception as exc:
if can_sentry():
sentry_sdk.capture_exception(exc)
context = {'body': get_publisher().finish_failed_request()}
self.quixote_response = get_request().response

View File

@ -312,11 +312,6 @@ class QommonPublisher(Publisher, object):
# were configured to be mailed.
pass
try:
self.get_app_logger().error('internal server error')
except:
pass
if exc_type is SystemExit:
raise exc_type