use of com.azure.core.exception.HttpResponseException in project azure-maven-plugins by microsoft.
the class AzureMessage method getCause.
@Nullable
protected String getCause(@Nonnull Throwable throwable) {
final Throwable root = getRecognizableCause(throwable);
if (Objects.isNull(root)) {
return ExceptionUtils.getRootCause(throwable).toString();
}
String cause = null;
if (root instanceof ManagementException) {
cause = ((ManagementException) root).getValue().getMessage();
} else if (root instanceof HttpResponseException) {
cause = ((HttpResponseException) root).getResponse().getBodyAsString().block();
}
final String causeMsg = StringUtils.firstNonBlank(cause, root.getMessage());
return Optional.ofNullable(causeMsg).filter(StringUtils::isNotBlank).map(StringUtils::uncapitalize).map(c -> c.endsWith(".") ? c : c + '.').orElse(null);
}
use of com.azure.core.exception.HttpResponseException in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2 method getSettings.
/**
* Obtain current settings that have been configured within the UI.
*/
@Override
public Mono<String> getSettings(Date oldTimeStamp) {
URL requestUrl = getSettingsPath(oldTimeStamp);
LOGGER.debug("Settings pull request: {}", requestUrl);
HttpRequest request = new HttpRequest(HttpMethod.GET, requestUrl);
return httpPipeline.send(request).flatMap(response -> {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
return Mono.error(new AssertionError("http response mono returned empty"));
}
if (response.getStatusCode() >= 300) {
consumeResponseBody(response);
return Mono.error(new HttpResponseException(response));
}
return response.getBodyAsString();
});
}
use of com.azure.core.exception.HttpResponseException in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2 method getUploadAccess.
/**
* Obtain permission to upload a profile to service profiler.
*/
@Override
public Mono<BlobAccessPass> getUploadAccess(UUID profileId) {
URL requestUrl = uploadRequestUri(profileId);
LOGGER.debug("Etl upload access request: {}", requestUrl);
return executePostWithRedirect(requestUrl).map(response -> {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("http response mono returned empty");
}
// response body is not consumed below
consumeResponseBody(response);
if (response.getStatusCode() >= 300) {
throw new HttpResponseException(response);
}
String location = response.getHeaderValue("Location");
if (location == null || location.isEmpty()) {
throw new AssertionError("response did not have a location");
}
return new BlobAccessPass(null, location, null);
});
}
Aggregations