Done ticket GEPAFINBE-216 Handled error for appointment creation failed, now returning the error description getting from third party API.

This commit is contained in:
rajesh
2025-05-13 18:02:43 +05:30
parent d1dcc5cf7b
commit 5e3b0025d9
2 changed files with 27 additions and 6 deletions

View File

@@ -544,7 +544,9 @@ public class GepafinConstant {
public static final String NO_EMAIL_LOG_FOUND = "no.email.log.msg";
public static final String USER_ACTION_ID_NOT_FOUND = "user.action.id.not.found";
public static final String CAUSE_STRING = "cause" ;
public static final String ERROR_DESCRIPTION_STRING = "errorDescription" ;
public static final String ERROR_STRING = "errors";
}

View File

@@ -758,12 +758,31 @@ public class AppointmentDao {
if (appointmentResponse.getBody() != null) {
log.info("Appointment API Response : {}", appointmentResponse.getBody());
Map<String, Object> responseBody = (Map<String, Object>) appointmentResponse.getBody();
if (responseBody.containsKey(GepafinConstant.DATA_STRING)) {
Map<String, Object> data = (Map<String, Object>) responseBody.get(GepafinConstant.DATA_STRING);
if (data != null && data.containsKey(GepafinConstant.ID_STRING)) {
return data.get(GepafinConstant.ID_STRING).toString();
try {
Map<String, Object> responseBody = (Map<String, Object>) appointmentResponse.getBody();
// 1. Try to get appointment ID from data.id
if (responseBody.containsKey(GepafinConstant.DATA_STRING)) {
Map<String, Object> data = (Map<String, Object>) responseBody.get(GepafinConstant.DATA_STRING);
if (data != null && data.containsKey(GepafinConstant.ID_STRING)) {
return data.get(GepafinConstant.ID_STRING).toString();
}
}
// 2. If ID not present, check errors[0].cause.errorDescription
if (responseBody.containsKey(GepafinConstant.ERROR_STRING)) {
List<Map<String, Object>> errors = (List<Map<String, Object>>) responseBody.get(GepafinConstant.ERROR_STRING);
if (errors != null && !errors.isEmpty()) {
Map<String, Object> firstError = errors.get(0);
if (firstError.containsKey(GepafinConstant.CAUSE_STRING)) {
Map<String, Object> cause = (Map<String, Object>) firstError.get(GepafinConstant.CAUSE_STRING);
if (cause != null && cause.containsKey(GepafinConstant.ERROR_DESCRIPTION_STRING)) {
String errorDescription = cause.get(GepafinConstant.ERROR_DESCRIPTION_STRING).toString();
log.warn("Appointment creation failed: {}", errorDescription);
}
}
}
}
} catch (Exception e) {
log.error("Error while extracting appointment ID or parsing error message", e);
}
}
return null;