From f8afe2360e06a753b859ee386d8d5c30e0fa1f24 Mon Sep 17 00:00:00 2001 From: imesh94 Date: Thu, 14 Nov 2024 13:50:26 +0530 Subject: [PATCH 1/2] Skip formatting errors in backend error scenarios --- .../cds/gateway/mediators/GatewayErrorMediator.java | 9 +++++++-- .../openbanking/cds/gateway/utils/GatewayConstants.java | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/mediators/GatewayErrorMediator.java b/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/mediators/GatewayErrorMediator.java index d6b73098..09e91d49 100644 --- a/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/mediators/GatewayErrorMediator.java +++ b/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/mediators/GatewayErrorMediator.java @@ -82,6 +82,9 @@ public boolean mediate(MessageContext messageContext) { // Error handling logic. JSONObject errorData; + String statusCodeString = extractStatusCode(messageContext); + int statusCode = Integer.parseInt(statusCodeString); + if ((messageContext.getProperty(GatewayConstants.ERROR_CODE)) != null) { int errorCode = (int) messageContext.getProperty(GatewayConstants.ERROR_CODE); @@ -109,12 +112,14 @@ public boolean mediate(MessageContext messageContext) { // Assume the errors thrown from the relevant internal webapps of these APIs are // already formatted according to the CDS format return true; + } else if (messageContext.getProperty(GatewayConstants.ENDPOINT_ADDRESS) != null && + statusCode != HttpStatus.SC_REQUEST_TIMEOUT) { + // Assume the errors coming from the backend are properly formatted. + return true; } else { - String statusCodeString = extractStatusCode(messageContext); if (StringUtils.isBlank(statusCodeString)) { return true; } - int statusCode = Integer.parseInt(statusCodeString); ErrorConstants.AUErrorEnum errorEnum; if ("406".equals(statusCodeString)) { errorEnum = ErrorConstants.AUErrorEnum.INVALID_ACCEPT_HEADER; diff --git a/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java b/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java index 03049089..7c00b164 100644 --- a/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java +++ b/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java @@ -137,6 +137,8 @@ private GatewayConstants() { public static final String REST_METHOD = "REST_METHOD"; public static final String OAUTH_JWT_ASSERTION = "client_assertion"; public static final String CLIENT_ID = "client_id"; + public static final String ENDPOINT_ADDRESS = "ENDPOINT_ADDRESS"; + // Constants related to executors public static final String HTTP_GET = "GET"; From d55f2870fb7b5766c6ed780d390bee8ec54dce26 Mon Sep 17 00:00:00 2001 From: imesh94 Date: Thu, 14 Nov 2024 13:55:11 +0530 Subject: [PATCH 2/2] Remove additional newline --- .../org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java b/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java index 7c00b164..13c8c3a6 100644 --- a/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java +++ b/components/org.wso2.openbanking.cds.gateway/src/main/java/org/wso2/openbanking/cds/gateway/utils/GatewayConstants.java @@ -139,7 +139,6 @@ private GatewayConstants() { public static final String CLIENT_ID = "client_id"; public static final String ENDPOINT_ADDRESS = "ENDPOINT_ADDRESS"; - // Constants related to executors public static final String HTTP_GET = "GET"; public static final String HTTP_POST = "POST";