def handle_annotation_event(self, event): """ Process an annotation event, taking appropriate action to the event. This will attempt to fulfill the request synchronously if asked, or fall back on a delayed celery task if not or if this fails. :param event: AnnotationEvent object """ if event.action in ["create", "update"]: sync_handler, async_task = self.add_annotation_by_id, indexer.add_annotation elif event.action == "delete": sync_handler, async_task = ( self.delete_annotation_by_id, indexer.delete_annotation, ) else: return False try: return sync_handler(event.annotation_id) except Exception as err: # pylint: disable=broad-except report_exception(err) # Either the synchronous method was disabled, or failed... return async_task.delay(event.annotation_id)
def other_exceptions(exc, request): """Catch all errors (Pyramid or Python) and display an HTML page.""" # We don't want to log errors from upstream services or things which are # the user goofing about making bad queries. if not isinstance(exc, (UpstreamServiceError, BadURL, HTTPClientError)): h_pyramid_sentry.report_exception(exc) return _get_error_body(exc, request)
def google_drive_exceptions(exc, request): """Catch all errors for Google Drive and display an HTML page.""" # Don't log 404's as they aren't very interesting if not isinstance(exc, HTTPNotFound): h_pyramid_sentry.report_exception(exc) _set_status(exc, request) data = { "exception": exc.__class__.__name__, "message": str(exc.args[0]) if exc.args else None, } if hasattr(exc, "response") and exc.response is not None: data["upstream"] = _serialise_requests_info(exc.request, exc.response) return data
def publish_all(self): while True: try: event = self.queue.popleft() except IndexError: break # Get subscribers to event and invoke them. The normal way to do # this in Pyramid is to invoke `registry.notify`, but that provides # no guarantee about the order of execution and any failure causes # later subscribers not to run. # # Here we wrap each subscriber call in an exception handler to # make failure independent in non-debug environments. subscribers = _get_subscribers(self.request.registry, event) for subscriber in subscribers: try: subscriber(event) except Exception: if event.request.debug: raise report_exception()
def test_exc_defaults_to_none(self, sentry_sdk): report_exception() sentry_sdk.capture_exception.assert_called_once_with(None)
def test_it_reports_the_exception_to_sentry(self, sentry_sdk): exc = ValueError("Test exception") report_exception(exc) sentry_sdk.capture_exception.assert_called_once_with(exc)