if (((HttpResponseException) ex).getStatusCode() == NOT_FOUND) {
Map<String, String> props = new HashMap<>();
props.put(NAME, po.getCommonName());
props.put(LOCATION, template.getLocation().location());
props.put(DESCRIPTION, template.getDescription());
HttpResponseDecorator affinityResponse = (HttpResponseDecorator) po.getAzureClient().createAffinityGroup(props);
String requestId = (String) po.getAzureClient().getRequestId(affinityResponse);
waitUntilComplete(po.getAzureClient(), requestId);
} else if (ex instanceof HttpResponseException) {
LOGGER.error(String.format("Error occurs on %s stack under the affinity group creation", stack.getId()), ex);
throw new InternalServerException(((HttpResponseException) ex).getResponse().toString());