Skip to content

Commit

Permalink
Merge pull request #7 from pm4ml/mmd-2026
Browse files Browse the repository at this point in the history
mmd-2026: Update GET /transfers response and add error handling
  • Loading branch information
gibaros authored Feb 4, 2022
2 parents 856ba75 + 1b411f4 commit d74a610
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 9 deletions.
16 changes: 14 additions & 2 deletions core-connector-interface/src/main/resources/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/mojaloopTransferState'
$ref: '#/components/schemas/transferStatusResponse'
400:
$ref: '#/components/responses/400'
404:
Expand Down Expand Up @@ -1638,6 +1638,18 @@ components:
- WAITING_FOR_QUOTE_ACCEPTANCE `AUTO_ACCEPT_QUOTE` is set to "false" and quote information has been returned, waiting to be accepted by the Payer DFSP using a `PUT /sendmoney/{transferId}` request.
- COMPLETED The transfer has completed successfully.
transferStatusResponse:
type: object
properties:
transferId:
$ref: '#/components/schemas/mojaloopIdentifier'
transferState:
$ref: '#/components/schemas/transferStatus'
completedTimestamp:
$ref: '#/components/schemas/timestamp'
description: Time and date when the transaction was completed.
example: "2020-05-19T08:38:08.699-04:00"

responses:
'400':
description: Malformed or missing required headers or parameters
Expand Down Expand Up @@ -1719,4 +1731,4 @@ components:
schema:
pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
type: string
description: Transfer identifier.
description: Transfer identifier.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions core-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@
<dependency>
<groupId>com.modus.adapter.exception</groupId>
<artifactId>cbs-adapters-exception-handling</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/core-connectors-camel-common-1.1.1-SNAPSHOT.jar</systemPath>
<systemPath>${basedir}/lib/core-connectors-camel-common-1.1.3-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.modusbox.client.api.TransfersApi;
import com.modusbox.client.model.FulfilNotification;
import com.modusbox.client.model.MojaloopTransferState;
import com.modusbox.client.model.TransferStatusResponse;
import com.modusbox.client.model.TransferRequestInbound;
import com.modusbox.client.model.TransferResponseInbound;

Expand All @@ -12,7 +12,7 @@
public class TransfersApiImpl implements TransfersApi {

@Override
public MojaloopTransferState getTransfersByTransferId(@Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$") String transferId) {
public TransferStatusResponse getTransfersByTransferId(@Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$") String transferId) {
return null;
}

Expand Down
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));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.modusbox.client.processor.CheckCBSError;
import com.modusbox.client.processor.CustomErrorProcessor;
import com.modusbox.client.processor.CheckMojaloopError;
import org.apache.camel.builder.RouteBuilder;

public final class CustomErrorRouter extends RouteBuilder {
private CustomErrorProcessor customErrorProcessor = new CustomErrorProcessor();
private CheckCBSError checkCBSError = new CheckCBSError();
private CheckMojaloopError checkMojaloopError = new CheckMojaloopError();

public void configure() {

Expand All @@ -18,5 +20,10 @@ public void configure() {
//.process(exchange -> System.out.println())
.process(checkCBSError)
;

from("direct:catchMojaloopError")
// .process(exchange -> System.out.println())
.process(checkMojaloopError)
;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,22 @@ public void configure() {
"'Tracking the response', 'Verify the response', null)")
// .process(exchange -> System.out.println())

.choice()
.when(simple("${body['statusCode']} != null"))
// .process(exchange -> System.out.println())
.to("direct:catchMojaloopError")
.endDoTry()

// .process(exchange -> System.out.println())

.choice()
.when(simple("${body['fulfil']} != null"))
// .process(exchange -> System.out.println())
.marshal().json()
.transform(datasonnet("resource:classpath:mappings/getTransfersResponse.ds"))
.setBody(simple("${body.content}"))
.marshal().json()
.endDoTry()

/*
* END processing
Expand All @@ -101,6 +113,8 @@ public void configure() {
"'Final Response: ${body}', " +
"null, null, 'Response of GET /transfers/${header.transferId} API')")

.doCatch(CCCustomException.class, HttpOperationFailedException.class, JSONException.class)
.to("direct:extractCustomErrors")
.doFinally().process(exchange -> {
((Histogram.Timer) exchange.getProperty(TIMER_NAME_GET)).observeDuration(); // stop Prometheus Histogram metric
}).end()
Expand Down
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
}

0 comments on commit d74a610

Please sign in to comment.