Skip to content

Commit

Permalink
Add loggin to project view page: add why we get 400 in log
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Sep 16, 2024
1 parent 1f4dd18 commit 563fe41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion onadata/apps/api/viewsets/project_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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()

Expand Down Expand Up @@ -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(f"%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)
Expand Down
1 change: 1 addition & 0 deletions onadata/libs/utils/common_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 563fe41

Please sign in to comment.