com.microsoft.azure.CloudError Java Examples
The following examples show how to use
com.microsoft.azure.CloudError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DnsZoneRecordSetETagTests.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Runs the action and assert that action throws CloudException with CloudError.Code * property set to 'PreconditionFailed'. * * @param action action to run */ private void ensureETagExceptionIsThrown(final Action0 action) { boolean isCloudExceptionThrown = false; boolean isCloudErrorSet = false; boolean isPreconditionFailedCodeSet = false; try { action.call(); } catch (CloudException exception) { isCloudExceptionThrown = true; CloudError cloudError = exception.body(); if (cloudError != null) { isCloudErrorSet = true; isPreconditionFailedCodeSet = cloudError.code().contains("PreconditionFailed"); } } Assert.assertTrue("Expected CloudException is not thrown", isCloudExceptionThrown); Assert.assertTrue("Expected CloudError property is not set in CloudException", isCloudErrorSet); Assert.assertTrue("Expected PreconditionFailed code is not set indicating ETag concurrency check failure", isPreconditionFailedCodeSet); }
Example #2
Source File: CloudErrorDeserializer.java From autorest-clientruntime-for-java with MIT License | 6 votes |
@Override public CloudError deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { p.setCodec(mapper); JsonNode errorNode = p.readValueAsTree(); if (errorNode == null) { return null; } if (errorNode.get("error") != null) { errorNode = errorNode.get("error"); } JsonParser parser = new JsonFactory().createParser(errorNode.toString()); parser.setCodec(mapper); return parser.readValueAs(CloudError.class); }
Example #3
Source File: AzureUtils.java From cloudbreak with Apache License 2.0 | 6 votes |
private Optional<String> getErrorMessage(String resourceType, String resourceId, CloudException e) { CloudError cloudError = e.body(); if (cloudError == null) { return Optional.of(String.format("%s %s deletion failed: '%s', please go to Azure Portal for details", resourceType, resourceId, e.getMessage())); } String errorCode = cloudError.code(); if ("ResourceGroupNotFound".equals(errorCode)) { LOGGER.warn("{} {} does not exist, assuming that it has already been deleted", resourceType, resourceId); return Optional.empty(); // leave errorMessage null => do not throw exception } else { String details = cloudError.details() != null ? cloudError.details().stream().map(CloudError::message).collect(Collectors.joining(", ")) : ""; return Optional.of(String.format("%s %s deletion failed, status code %s, error message: %s, details: %s", resourceType, resourceId, errorCode, cloudError.message(), details)); } }
Example #4
Source File: ProviderRegistrationInterceptor.java From azure-libraries-for-java with MIT License | 5 votes |
@Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); if (!response.isSuccessful()) { String content = Utils.getResponseBodyInString(response.body()); AzureJacksonAdapter jacksonAdapter = new AzureJacksonAdapter(); CloudError cloudError = jacksonAdapter.deserialize(content, CloudError.class); if (cloudError != null && "MissingSubscriptionRegistration".equals(cloudError.code())) { Pattern pattern = Pattern.compile("/subscriptions/([\\w-]+)/", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(chain.request().url().toString()); matcher.find(); RestClient.Builder restClientBuilder = new RestClient.Builder(); restClientBuilder.withBaseUrl("https://" + chain.request().url().host()) .withCredentials(credentials) .withSerializerAdapter(jacksonAdapter) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()); if (credentials.proxy() != null) { restClientBuilder.withProxy(credentials.proxy()); } RestClient restClient = restClientBuilder.build(); ResourceManager resourceManager = ResourceManager.authenticate(restClient) .withSubscription(matcher.group(1)); pattern = Pattern.compile(".*'(.*)'"); matcher = pattern.matcher(cloudError.message()); matcher.find(); Provider provider = registerProvider(matcher.group(1), resourceManager); while (provider.registrationState().equalsIgnoreCase("Unregistered") || provider.registrationState().equalsIgnoreCase("Registering")) { SdkContext.sleep(5 * 1000); provider = resourceManager.providers().getByName(provider.namespace()); } // Retry response = chain.proceed(chain.request()); } } return response; }
Example #5
Source File: CloudErrorDeserializer.java From autorest-clientruntime-for-java with MIT License | 2 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations. * @return a simple module to be plugged onto Jackson ObjectMapper. */ static SimpleModule getModule(ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.addDeserializer(CloudError.class, new CloudErrorDeserializer(mapper)); return module; }