in data/src/main/java/com/microsoft/azure/kusto/data/BaseClient.java [131:171]
public static DataServiceException createExceptionFromResponse(String url, HttpResponse httpResponse, Exception thrownException, String errorFromResponse) {
if (httpResponse == null) {
return new DataServiceException(url, "POST failed to send request", thrownException, false);
}
/*
* TODO: When we add another streaming API that returns a KustoOperationResult, we'll need to handle the 2 types of content errors this API can return:
* (1) Inline error (engine identifies error after it starts building the json result), or (2) in the KustoOperationResult's QueryCompletionInformation,
* both of which present with "200 OK". See .Net's DataReaderParser.
*/
String activityId = determineActivityId(httpResponse);
String message = errorFromResponse;
WebException formattedException = new WebException(errorFromResponse, httpResponse, thrownException);
boolean isPermanent = false;
if (!StringUtils.isBlank(errorFromResponse)) {
try {
JsonNode jsonObject = Utils.getObjectMapper().readTree(errorFromResponse);
if (jsonObject.has("error")) {
formattedException = new DataWebException(errorFromResponse, httpResponse, thrownException);
OneApiError apiError = ((DataWebException) formattedException).getApiError();
message = apiError.getDescription();
isPermanent = apiError.isPermanent();
} else if (jsonObject.has("message")) {
message = jsonObject.get("message").asText();
}
} catch (JsonProcessingException e) {
// It's not ideal to use an exception here for control flow, but we can't know if it's a valid JSON until we try to parse it
LOGGER.debug("json processing error happened while parsing errorFromResponse {}", e.getMessage(), e);
}
} else {
if (httpResponse.getStatusCode() == HttpStatus.FORBIDDEN || httpResponse.getStatusCode() == HttpStatus.UNAUTHORIZED) {
isPermanent = true;
}
message = String.format("Http StatusCode='%s'", httpResponse.getStatusCode());
}
return new DataServiceException(
url,
String.format("%s, ActivityId='%s'", message, activityId),
formattedException,
isPermanent);
}