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:
@@ -544,7 +544,9 @@ public class GepafinConstant {
|
|||||||
public static final String NO_EMAIL_LOG_FOUND = "no.email.log.msg";
|
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 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";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -758,12 +758,31 @@ public class AppointmentDao {
|
|||||||
|
|
||||||
if (appointmentResponse.getBody() != null) {
|
if (appointmentResponse.getBody() != null) {
|
||||||
log.info("Appointment API Response : {}", appointmentResponse.getBody());
|
log.info("Appointment API Response : {}", appointmentResponse.getBody());
|
||||||
Map<String, Object> responseBody = (Map<String, Object>) appointmentResponse.getBody();
|
try {
|
||||||
if (responseBody.containsKey(GepafinConstant.DATA_STRING)) {
|
Map<String, Object> responseBody = (Map<String, Object>) appointmentResponse.getBody();
|
||||||
Map<String, Object> data = (Map<String, Object>) responseBody.get(GepafinConstant.DATA_STRING);
|
// 1. Try to get appointment ID from data.id
|
||||||
if (data != null && data.containsKey(GepafinConstant.ID_STRING)) {
|
if (responseBody.containsKey(GepafinConstant.DATA_STRING)) {
|
||||||
return data.get(GepafinConstant.ID_STRING).toString();
|
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;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user