Open vijayg10 opened 3 months ago
There're several places, which cause that error and need to be improved:
Currently simulator returns 500 status code error (in case if party already exists) instead of 400 or 409
After that sendRequest
component from central-services-shared converts Axios error to _DESTINATION_COMMUNICATIONERROR FSPIOPError
(code - 1001; httpStatusCode - 503):
https://github.com/mojaloop/central-services-shared/blob/main/src/util/request.js#L145
{
"name": "FSPIOPError",
"cause": {
"message": "Request failed with status code 500",
"name": "AxiosError",
"stack": "AxiosError: Request failed with status code 500\n at settle (/opt/app/node_modules/axios/dist/node/axios.cjs:1967:12)\n at IncomingMessage.handleStreamEnd (/opt/app/node_modules/axios/dist/node/axios.cjs:3066:11)\n at IncomingMessage.emit (node:events:526:35)\n at endReadableNT (node:internal/streams/readable:1359:12)\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21)\n at Axios.request (/opt/app/node_modules/axios/dist/node/axios.cjs:3877:41)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async Object.sendRequest (/opt/app/node_modules/@mojaloop/central-services-shared/src/util/request.js:122:22)\n at async exports.oracleRequest (/opt/app/src/models/oracle/facade.js:109:14)\n at async Object.postParticipants (/opt/app/src/domain/participants/participants.js:287:26)",
"config": {
"url": "http://simulator:8444/oracle/participants/MSISDN/27713803912",
"method": "post",
"data": "{\"fspId\":\"greenbankfsp\",\"currency\":\"BWP\"}",
"responseType": "json"
},
"code": "ERR_BAD_RESPONSE",
"status": 500
},
"replyTo": "greenbankfsp",
"apiErrorCode": {
"code": "1001",
"message": "Destination communication error",
"name": "DESTINATION_COMMUNICATION_ERROR",
"type": {
"regex": "^10[0-9]{2}$",
"description": "Generic Communication Error",
"httpStatusCode": 503,
"name": "GENERIC_COMMUNICATION_ERROR"
},
"httpStatusCode": 503
},
"httpStatusCode": 503,
"extensions": [
{
"key": "status",
"value": 500
},
{
"key": "cause",
"value": "[{\"key\":\"url\",\"value\":\"http://simulator:8444/oracle/participants/MSISDN/27713803912\"},{\"key\":\"sourceFsp\",\"value\":\"greenbankfsp\"},{\"key\":\"destinationFsp\",\"value\":\"switch\"},{\"key\":\"method\",\"value\":\"POST\"},{\"key\":\"request\",\"value\":\"{\\\"url\\\":\\\"http://simulator:8444/oracle/participants/MSISDN/27713803912\\\",\\\"method\\\":\\\"POST\\\",\\\"headers\\\":{\\\"content-type\\\":\\\"application/vnd.interoperability.participants+json;version=1.0\\\",\\\"fspiop-source\\\":\\\"greenbankfsp\\\",\\\"authorization\\\":\\\"{$inputs.PAYEE_BEARER_TOKEN}\\\",\\\"accept\\\":\\\"application/vnd.interoperability.participants+json;version=1.0\\\",\\\"date\\\":\\\"Tue, 09 Apr 2024 20:09:12 GMT\\\",\\\"traceparent\\\":\\\"00-aabba234a60e91b087c1853418eb6c1b-0123456789abcdef0-00\\\",\\\"user-agent\\\":\\\"axios/0.27.2\\\",\\\"connection\\\":\\\"keep-alive\\\",\\\"traceid\\\":\\\"4b205035-fa19-4713-b984-edd15177ed78\\\",\\\"fspiop-destination\\\":\\\"switch\\\"},\\\"data\\\":{\\\"fspId\\\":\\\"greenbankfsp\\\",\\\"currency\\\":\\\"BWP\\\"},\\\"responseType\\\":\\\"json\\\"}\"},{\"key\":\"errorMessage\",\"value\":\"Request failed with status code 500\"},{\"key\":\"status\",\"value\":500},{\"key\":\"response\",\"value\":{\"errorInformation\":{\"errorCode\":\"2001\",\"errorDescription\":\"Internal server error - ID:27713803912 already exists\"}}}]"
}
]
}
And then ALS perform quite weird error handling, which should be reviewed: https://github.com/mojaloop/account-lookup-service/blob/main/src/models/oracle/facade.js#L126-L139
Note: added unit test to reproduce the bug: https://github.com/mojaloop/account-lookup-service/blob/fix/3838/test/unit/models/oracle/facade.test.js#L451
Summary: When I send a POST /participants/{Type}/{ID} request to ALS for creating a mapping in the oracle, it the party is already exists in the oracle, then I am getting the following error in the error callback. Instead it should be something like
Party already exists
Severity: (Low, Medium, High)
Priority: (Critical, Medium, Low)
Specifications