Search in sources :

Example 1 with HttpResponseException

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);
}
Also used : Setter(lombok.Setter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Accessors(lombok.experimental.Accessors) Getter(lombok.Getter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AzureToolkitException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitException) HttpResponseException(com.azure.core.exception.HttpResponseException) AzureOperationRef(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) ManagementException(com.azure.core.management.exception.ManagementException) AzureTaskContext(com.microsoft.azure.toolkit.lib.common.task.AzureTaskContext) Objects(java.util.Objects) List(java.util.List) Action(com.microsoft.azure.toolkit.lib.common.action.Action) Optional(java.util.Optional) AzureOperationException(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationException) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) ManagementException(com.azure.core.management.exception.ManagementException) StringUtils(org.apache.commons.lang3.StringUtils) HttpResponseException(com.azure.core.exception.HttpResponseException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Nullable(javax.annotation.Nullable)

Example 2 with HttpResponseException

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();
    });
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) HttpResponseException(com.azure.core.exception.HttpResponseException) URL(java.net.URL)

Example 3 with HttpResponseException

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);
    });
}
Also used : BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) HttpResponseException(com.azure.core.exception.HttpResponseException) URL(java.net.URL)

Aggregations

HttpResponseException (com.azure.core.exception.HttpResponseException)3 URL (java.net.URL)2 HttpRequest (com.azure.core.http.HttpRequest)1 ManagementException (com.azure.core.management.exception.ManagementException)1 Streams (com.google.common.collect.Streams)1 BlobAccessPass (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass)1 Action (com.microsoft.azure.toolkit.lib.common.action.Action)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 Cacheable (com.microsoft.azure.toolkit.lib.common.cache.Cacheable)1 AzureToolkitException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitException)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)1 AzureOperationException (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationException)1 AzureOperationRef (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef)1 IAzureOperation (com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation)1 AzureTaskContext (com.microsoft.azure.toolkit.lib.common.task.AzureTaskContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1