-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from pm4ml/mmd-2026
mmd-2026: Update GET /transfers response and add error handling
- Loading branch information
Showing
9 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core-connector/src/main/java/com/modusbox/client/processor/CheckMojaloopError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.modusbox.client.processor; | ||
|
||
import com.google.gson.Gson; | ||
import com.modusbox.client.customexception.CCCustomException; | ||
import com.modusbox.client.enums.ErrorCode; | ||
import com.modusbox.log4j2.message.CustomJsonMessage; | ||
import com.modusbox.log4j2.message.CustomJsonMessageImpl; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.Processor; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.LinkedHashMap; | ||
|
||
public class CheckMojaloopError implements Processor { | ||
|
||
CustomJsonMessage customJsonMessage = new CustomJsonMessageImpl(); | ||
|
||
public void process(Exchange exchange) throws Exception { | ||
Gson gson = new Gson(); | ||
String s = gson.toJson(exchange.getIn().getBody(), LinkedHashMap.class); | ||
JSONObject respObject = new JSONObject(s); | ||
int errorCode = 0; | ||
String errorMessage = ""; | ||
|
||
try { | ||
errorCode = respObject.getInt("statusCode"); | ||
errorMessage = respObject.getString("message"); | ||
if (errorCode == 3208) { | ||
customJsonMessage.logJsonMessage("error", String.valueOf(exchange.getIn().getHeader("X-CorrelationId")), | ||
"Processing the exception at CheckMojaloopError", null, null, respObject.toString()); | ||
throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.TRANSFER_ID_NOT_FOUND)); | ||
} | ||
else if (errorCode == 400) { | ||
customJsonMessage.logJsonMessage("error", String.valueOf(exchange.getIn().getHeader("X-CorrelationId")), | ||
"Processing the exception at CheckMojaloopError", null, null, respObject.toString()); | ||
if (errorMessage.startsWith(".path.transferId should match pattern")) { | ||
throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.MALFORMED_SYNTAX)); | ||
} | ||
else { | ||
throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.GENERIC_VALIDATION_ERROR)); | ||
} | ||
} | ||
else { | ||
customJsonMessage.logJsonMessage("error", String.valueOf(exchange.getIn().getHeader("X-CorrelationId")), | ||
"Processing the exception at CheckMojaloopError, unhandled error code", null, null, respObject.toString()); | ||
throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR, "Error while retrieving transfer state, please retry later.")); | ||
} | ||
} catch (JSONException e) { | ||
System.out.println("Problem extracting error code from Mojaloop error response occurred."); | ||
throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR)); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
core-connector/src/main/resources/mappings/getTransfersResponse.ds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"mojaloopTransferState": payload.fulfil.body.transferState | ||
} | ||
"transferId": payload.transferId, | ||
"transferState": payload.fulfil.body.transferState, | ||
"completedTimestamp": payload.fulfil.body.completedTimestamp | ||
} |