Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABDM: Log the errors instead of sending them as a response #1821

Merged
merged 7 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions care/abdm/api/viewsets/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from datetime import datetime, timedelta

from django.core.cache import cache
Expand All @@ -14,6 +15,8 @@
from care.facility.models.patient_consultation import PatientConsultation
from config.authentication import ABDMAuthentication

logger = logging.getLogger(__name__)


class OnFetchView(GenericAPIView):
permission_classes = (IsAuthenticated,)
Expand All @@ -25,7 +28,14 @@
try:
AbdmGateway().init(data["resp"]["requestId"])
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
logger.warning(

Check warning on line 31 in care/abdm/api/viewsets/auth.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/auth.py#L31

Added line #L31 was not covered by tests
f"Error: OnFetchView::post failed while initialising ABDM Gateway, Reason: {e}",
exc_info=True,
)
return Response(

Check warning on line 35 in care/abdm/api/viewsets/auth.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/auth.py#L35

Added line #L35 was not covered by tests
{"detail": "Error: Initialising ABDM Gateway failed."},
status=status.HTTP_400_BAD_REQUEST,
)

return Response({}, status=status.HTTP_202_ACCEPTED)

Expand Down Expand Up @@ -346,10 +356,13 @@
}
)
except Exception as e:
logger.warning(

Check warning on line 359 in care/abdm/api/viewsets/auth.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/auth.py#L359

Added line #L359 was not covered by tests
f"Error: RequestDataView::post failed to notify (health-information/notify). Reason: {e}",
exc_info=True,
)
return Response(
{
"detail": "Failed to notify (health-information/notify)",
"error": str(e),
},
status=status.HTTP_400_BAD_REQUEST,
)
Expand Down
36 changes: 32 additions & 4 deletions care/abdm/api/viewsets/healthid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ABDM HealthID APIs

import logging
from datetime import datetime

from drf_spectacular.utils import extend_schema
Expand Down Expand Up @@ -31,6 +32,8 @@
from config.auth_views import CaptchaRequiredException
from config.ratelimit import ratelimit

logger = logging.getLogger(__name__)


# API for Generating OTP for HealthID
class ABDMHealthIDViewSet(GenericViewSet, CreateModelMixin):
Expand Down Expand Up @@ -363,8 +366,14 @@
}
)
except Exception as e:
logger.warning(

Check warning on line 369 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L369

Added line #L369 was not covered by tests
f"Error: ABDMHealthIDViewSet::link_via_qr failed to fetch modes. Reason: {e}",
exc_info=True,
)
return Response(
{"detail": "Failed to fetch modes", "error": str(e)},
{
"detail": "Failed to fetch modes",
},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -419,8 +428,15 @@
}
)
except Exception as e:
logger.warning(

Check warning on line 431 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L431

Added line #L431 was not covered by tests
f"Error: ABDMHealthIDViewSet::get_new_linking_token failed to fetch modes. Reason: {e}",
exc_info=True,
)

return Response(
{"detail": "Failed to fetch modes", "error": str(e)},
{
"detail": "Failed to fetch modes",
},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -463,8 +479,15 @@
}
)
except Exception as e:
logger.warning(

Check warning on line 482 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L482

Added line #L482 was not covered by tests
f"Error: ABDMHealthIDViewSet::add_care_context failed. Reason: {e}",
exc_info=True,
)

return Response(
{"detail": "Failed to add care context", "error": str(e)},
{
"detail": "Failed to add care context",
},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -496,8 +519,13 @@
}
)
except Exception as e:
logger.warning(

Check warning on line 522 in care/abdm/api/viewsets/healthid.py

View check run for this annotation

Codecov / codecov/patch

care/abdm/api/viewsets/healthid.py#L522

Added line #L522 was not covered by tests
f"Error: ABDMHealthIDViewSet::patient_sms_notify failed to send SMS. Reason: {e}",
exc_info=True,
)

return Response(
{"detail": "Failed to send SMS", "error": str(e)},
{"detail": "Failed to send SMS"},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down