Merge pull request #283 from Kitzanos/feature/GEPAFINBE-216
GEPAFINBE-216 (Create Appointments Error)
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 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,13 +758,32 @@ public class AppointmentDao {
|
||||
|
||||
if (appointmentResponse.getBody() != null) {
|
||||
log.info("Appointment API Response : {}", appointmentResponse.getBody());
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user