public void handleError(HttpCommand command, HttpResponse response) {
   String content;
   try {
     content =
         response.getContent() != null ? Utils.toStringAndClose(response.getContent()) : null;
     if (content != null) {
       try {
         if (content.indexOf('<') >= 0) {
           AzureStorageError error =
               utils.parseAzureStorageErrorFromContent(command, response, content);
           command.setException(new AzureStorageResponseException(command, response, error));
         } else {
           command.setException(new HttpResponseException(command, response, content));
         }
       } catch (Exception he) {
         command.setException(new HttpResponseException(command, response, content));
         Utils.rethrowIfRuntime(he);
       }
     } else {
       command.setException(new HttpResponseException(command, response));
     }
   } catch (Exception e) {
     command.setException(new HttpResponseException(command, response));
     Utils.rethrowIfRuntime(e);
   }
 }
 AtmosStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
   if (response.getContent() != null) {
     try {
       String content = Utils.toStringAndClose(response.getContent());
       if (content != null && content.indexOf('<') >= 0)
         return utils.parseAtmosStorageErrorFromContent(
             command, response, Utils.toInputStream(content));
     } catch (IOException e) {
       logger.warn(e, "exception reading error from response", response);
     }
   }
   return null;
 }
 public void handleError(HttpCommand command, HttpResponse response) {
   Exception exception = new HttpResponseException(command, response);
   try {
     AtmosStorageError error = parseErrorFromContentOrNull(command, response);
     if (error != null && error.getCode() == 1016) {
       File file = new File(command.getRequest().getEndpoint().getPath());
       exception =
           new KeyAlreadyExistsException(file.getParentFile().getAbsolutePath(), file.getName());
     } else {
       switch (response.getStatusCode()) {
         case 401:
           exception =
               new AuthorizationException(
                   command.getRequest(),
                   error != null ? error.getMessage() : response.getStatusLine());
           break;
         case 404:
           if (!command.getRequest().getMethod().equals("DELETE")) {
             String message =
                 error != null
                     ? error.getMessage()
                     : String.format(
                         "%s -> %s",
                         command.getRequest().getRequestLine(), response.getStatusLine());
             String path = command.getRequest().getEndpoint().getPath();
             Matcher matcher = DIRECTORY_PATH.matcher(path);
             if (matcher.find()) {
               exception = new ContainerNotFoundException(matcher.group(1), message);
             } else {
               matcher = DIRECTORY_KEY_PATH.matcher(path);
               if (matcher.find()) {
                 exception = new KeyNotFoundException(matcher.group(1), matcher.group(2), message);
               }
             }
           }
           break;
         default:
           exception =
               error != null
                   ? new AtmosStorageResponseException(command, response, error)
                   : new HttpResponseException(command, response);
       }
     }
   } finally {
     Closeables.closeQuietly(response.getContent());
     command.setException(exception);
   }
 }