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 3 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
18 changes: 16 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 @@ def post(self, request, *args, **kwargs):
try:
AbdmGateway().init(data["resp"]["requestId"])
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
logger.warning(
f"Error: OnFetchView::post failed while initialising ABDM Gateway, Reason: {e}",
exc_info=True,
)
return Response(
{"error": "Error: Initialising ABDM Gateway failed."},
sainak marked this conversation as resolved.
Show resolved Hide resolved
status=status.HTTP_400_BAD_REQUEST,
)

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

Expand Down Expand Up @@ -346,10 +356,14 @@ def post(self, request, *args, **kwargs):
}
)
except Exception as e:
logger.warning(
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),
"error": "Error: Failed to notify",
sainak marked this conversation as resolved.
Show resolved Hide resolved
},
status=status.HTTP_400_BAD_REQUEST,
)
Expand Down
39 changes: 35 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,15 @@ def link_via_qr(self, request):
}
)
except Exception as e:
logger.warning(
f"Error: ABDMHealthIDViewSet::link_via_qr failed to fetch nodes. Reason: {e}",
sainak marked this conversation as resolved.
Show resolved Hide resolved
exc_info=True,
)
return Response(
{"detail": "Failed to fetch modes", "error": str(e)},
{
"detail": "Failed to fetch modes",
"error": "Error: ABDM Gateway node fetch failed",
sainak marked this conversation as resolved.
Show resolved Hide resolved
},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -419,8 +429,16 @@ def get_new_linking_token(self, request):
}
)
except Exception as e:
logger.warning(
f"Error: ABDMHealthIDViewSet::get_new_linking_token failed to fetch nodes. Reason: {e}",
sainak marked this conversation as resolved.
Show resolved Hide resolved
exc_info=True,
)

return Response(
{"detail": "Failed to fetch modes", "error": str(e)},
{
"detail": "Failed to fetch modes",
"error": "Error: failed to fetch nodes.",
sainak marked this conversation as resolved.
Show resolved Hide resolved
},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -463,8 +481,16 @@ def add_care_context(self, request, *args, **kwargs):
}
)
except Exception as e:
logger.warning(
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",
"error": "Error: Failed to integrate care.",
sainak marked this conversation as resolved.
Show resolved Hide resolved
sainak marked this conversation as resolved.
Show resolved Hide resolved
},
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down Expand Up @@ -496,8 +522,13 @@ def patient_sms_notify(self, request, *args, **kwargs):
}
)
except Exception as e:
logger.warning(
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", "error": "Error: SMS not sent."},
sainak marked this conversation as resolved.
Show resolved Hide resolved
status=status.HTTP_400_BAD_REQUEST,
)

Expand Down
2 changes: 1 addition & 1 deletion data/medibase.json
Original file line number Diff line number Diff line change
Expand Up @@ -1144305,4 +1144305,4 @@
"cims_class_link": "/india/drug/search?q=drugs+for+erectile+dysfunction&mtype=brand&code=10d",
"cims_class": "Drugs for Erectile Dysfunction",
"atc_classification": "G04BE03 - sildenafil ; Belongs to the class of drugs used in erectile dysfunction."
}]
}]
sainak marked this conversation as resolved.
Show resolved Hide resolved
sainak marked this conversation as resolved.
Show resolved Hide resolved