care icon indicating copy to clipboard operation
care copied to clipboard

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

Open khavinshankar opened this issue 1 year ago • 3 comments

refer: https://github.com/coronasafe/care/pull/1814

khavinshankar avatar Jan 09 '24 06:01 khavinshankar

Can I take this up?

So as I understand the issue, We have to log the error response instead of sending them as response in places like these in the abdm API?:

        try:
            AbdmGateway().init(data["resp"]["requestId"])
        except Exception as e:
            return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)

Questions:

  • What should be sent instead of the e object to the client instead?
  • This is how we should log instead right?
logger = logging.getLogger(__nane__)


def post(self, request, *args, **kwargs):
    data = request.data

    try:
        AbdmGateway().init(data["resp"]["requestId"])
    except Exception as e:
        logger.warning(f"Error while initialising ABDM Gateway: {e}", exc_info=True)
        return Response({ "error": "Something went wrong." }, status=status.HTTP_400_BAD_REQUEST)

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

ProCode2 avatar Jan 11 '24 10:01 ProCode2

Yes, that works, while logging, just use the function name or the endpoint, that should be enough.

khavinshankar avatar Jan 12 '24 03:01 khavinshankar

@khavinshankar Can you take a look at #1821 and see if it looks good?

ProCode2 avatar Jan 13 '24 18:01 ProCode2