class AWSUtils {

   public AWSError parseAWSErrorFromContent(HttpRequest request, HttpResponse response) {
      byte[] actualPayload = response.getPayload() != null ? closeClientButKeepContentStream(response) : null;
      if (actualPayload == null || actualPayload.length == 0)
         return null;
      if ("text/plain".equals(response.getPayload().getContentMetadata().getContentType()))
         return null;
      try {
         AWSError error = factory.create(errorHandlerProvider.get()).setContext(request).apply(response);
         if (error.getRequestId() == null)
            error.setRequestId(response.getFirstHeaderOrNull(requestId));
         error.setRequestToken(response.getFirstHeaderOrNull(requestToken));
         if ("SignatureDoesNotMatch".equals(error.getCode())) {
            error.setStringSigned(signer.createStringToSign(request));
            error.setSignature(signer.sign(error.getStringSigned()));
         }
         return error;
      } catch (RuntimeException e) {
         logger.warn(e, "error parsing error");
         return null;
      }
   }

   @Inject  AWSUtils(@Named(PROPERTY_HEADER_TAG) String headerTag, RequestSigner signer, Factory factory,
         Provider<ErrorHandler> errorHandlerProvider);

}