[UCOD][PRE-PROD][13]-Downstream call to crm/deposit failing while onboarding customer, not showing the root casuse of failure

UCOD-14
Omar Shahbaz 1 month ago
parent bb1edcd42c
commit df97346124

@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map; import java.util.Map;
@Service @Service
@ -52,17 +50,29 @@ public class WebClientCrmService {
private ApplicationExceptionMapper.APIError parseErrorDetails(WebClientResponseException e) { private ApplicationExceptionMapper.APIError parseErrorDetails(WebClientResponseException e) {
String errorCode = null; String errorCode = null;
List<String> arguments = null; Object[] arguments = new Object[0];
if (e.getResponseBodyAsString() != null) { if (e.getResponseBodyAsString() != null) {
try { try {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode errorNode = objectMapper.readTree(e.getResponseBodyAsString()); JsonNode errorNode = objectMapper.readTree(e.getResponseBodyAsString());
errorCode = errorNode.get("errorCode").asText(); JsonNode errorCodeNode = errorNode.get("errorCode");
arguments = Arrays.asList(objectMapper.convertValue(errorNode.get("arguments"), String[].class)); if (errorCodeNode != null && !errorCodeNode.isNull()) {
errorCode = errorCodeNode.asText();
} else {
JsonNode debugNode = errorNode.get("debugMessage");
errorCode = (debugNode != null && !debugNode.isNull()) ? debugNode.asText() : "ERR_REMOTE_" + e.getStatusCode().value();
}
JsonNode argsNode = errorNode.get("arguments");
if (argsNode != null && !argsNode.isNull()) {
arguments = objectMapper.convertValue(argsNode, String[].class);
}
} catch (IOException ex) { } catch (IOException ex) {
errorCode = "ERR_REMOTE_" + e.getStatusCode().value();
} }
} else {
errorCode = "ERR_REMOTE_" + e.getStatusCode().value();
} }
return new ApplicationExceptionMapper.APIError(errorCode, arguments.toArray()); return new ApplicationExceptionMapper.APIError(errorCode, arguments);
} }
} }

@ -12,8 +12,6 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@Service @Service
public class WebClientDepositService { public class WebClientDepositService {
@ -78,17 +76,29 @@ public class WebClientDepositService {
private ApplicationExceptionMapper.APIError parseErrorDetails(WebClientResponseException e) { private ApplicationExceptionMapper.APIError parseErrorDetails(WebClientResponseException e) {
String errorCode = null; String errorCode = null;
List<String> arguments = null; Object[] arguments = new Object[0];
if (e.getResponseBodyAsString() != null) { if (e.getResponseBodyAsString() != null) {
try { try {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode errorNode = objectMapper.readTree(e.getResponseBodyAsString()); JsonNode errorNode = objectMapper.readTree(e.getResponseBodyAsString());
errorCode = errorNode.get("errorCode").asText(); JsonNode errorCodeNode = errorNode.get("errorCode");
arguments = Arrays.asList(objectMapper.convertValue(errorNode.get("arguments"), String[].class)); if (errorCodeNode != null && !errorCodeNode.isNull()) {
errorCode = errorCodeNode.asText();
} else {
JsonNode debugNode = errorNode.get("debugMessage");
errorCode = (debugNode != null && !debugNode.isNull()) ? debugNode.asText() : "ERR_REMOTE_" + e.getStatusCode().value();
}
JsonNode argsNode = errorNode.get("arguments");
if (argsNode != null && !argsNode.isNull()) {
arguments = objectMapper.convertValue(argsNode, String[].class);
}
} catch (IOException ex) { } catch (IOException ex) {
errorCode = "ERR_REMOTE_" + e.getStatusCode().value();
} }
} else {
errorCode = "ERR_REMOTE_" + e.getStatusCode().value();
} }
return new ApplicationExceptionMapper.APIError(errorCode, arguments.toArray()); return new ApplicationExceptionMapper.APIError(errorCode, arguments);
} }
} }

Loading…
Cancel
Save