diff --git a/onadata/apps/api/viewsets/project_viewset.py b/onadata/apps/api/viewsets/project_viewset.py index c8e6797ce7..9112a0f414 100644 --- a/onadata/apps/api/viewsets/project_viewset.py +++ b/onadata/apps/api/viewsets/project_viewset.py @@ -2,6 +2,8 @@ """ The /projects API endpoint implementation. """ +import logging + from django.core.cache import cache from django.core.mail import send_mail from django.shortcuts import get_object_or_404 @@ -34,6 +36,7 @@ RemoveUserFromProjectSerializer, ShareProjectSerializer, ) +from onadata.libs.utils.common_tools import report_exception from onadata.libs.serializers.user_profile_serializer import UserProfileSerializer from onadata.libs.serializers.xform_serializer import ( XFormCreateSerializer, @@ -50,6 +53,8 @@ from onadata.libs.utils.project_utils import propagate_project_permissions_async from onadata.settings.common import DEFAULT_FROM_EMAIL, SHARE_PROJECT_SUBJECT +logger = logging.getLogger(__name__) + # pylint: disable=invalid-name BaseViewset = get_baseviewset_class() @@ -159,7 +164,13 @@ def forms(self, request, **kwargs): ) return Response(serializer.data, status=status.HTTP_201_CREATED) - + if survey['type'] and survey['text']: + error_message = f"{survey['type']}:{survey['text']}" + else: + error_message = f"{survey}" + message_subject = "Failed to upload form" + report_exception(message_subject, error_message) + logger.info("%s: %s", message_subject, error_message) return Response(survey, status=status.HTTP_400_BAD_REQUEST) xforms = XForm.objects.filter(project=project, deleted_at__isnull=True) diff --git a/onadata/libs/utils/common_tools.py b/onadata/libs/utils/common_tools.py index cc574ea42b..e59cd8785a 100644 --- a/onadata/libs/utils/common_tools.py +++ b/onadata/libs/utils/common_tools.py @@ -77,6 +77,7 @@ def report_exception(subject, info, exc_info=None): sentry_sdk.capture_exception(exc_info) else: message = f"{info}" + sentry_sdk.capture_message(f"{subject}: {info}") if settings.DEBUG or settings.TESTING_MODE: sys.stdout.write(f"Subject: {subject}\n")