use of org.apache.camel.component.salesforce.internal.dto.RestErrors in project camel by apache.
the class DefaultRestClient method createRestException.
@Override
protected SalesforceException createRestException(Response response, InputStream responseContent) {
// get status code and reason phrase
final int statusCode = response.getStatus();
String reason = response.getReason();
if (reason == null || reason.isEmpty()) {
reason = HttpStatus.getMessage(statusCode);
}
// try parsing response according to format
try {
if (responseContent != null && responseContent.available() > 0) {
final List<String> choices;
// return list of choices as error message for 300
if (statusCode == HttpStatus.MULTIPLE_CHOICES_300) {
if (PayloadFormat.JSON.equals(format)) {
choices = objectMapper.readValue(responseContent, TypeReferences.STRING_LIST_TYPE);
} else {
RestChoices restChoices = new RestChoices();
xStream.fromXML(responseContent, restChoices);
choices = restChoices.getUrls();
}
return new SalesforceMultipleChoicesException(reason, statusCode, choices);
} else {
final List<RestError> restErrors;
if (PayloadFormat.JSON.equals(format)) {
restErrors = objectMapper.readValue(responseContent, TypeReferences.REST_ERROR_LIST_TYPE);
} else {
RestErrors errors = new RestErrors();
xStream.fromXML(responseContent, errors);
restErrors = errors.getErrors();
}
return new SalesforceException(restErrors, statusCode);
}
}
} catch (IOException e) {
// log and ignore
String msg = "Unexpected Error parsing " + format + " error response body + [" + responseContent + "] : " + e.getMessage();
log.warn(msg, e);
} catch (RuntimeException e) {
// log and ignore
String msg = "Unexpected Error parsing " + format + " error response body + [" + responseContent + "] : " + e.getMessage();
log.warn(msg, e);
}
// just report HTTP status info
return new SalesforceException("Unexpected error: " + reason + ", with content: " + responseContent, statusCode);
}
Aggregations