/** * Always returns {@code null} since this exception represents a * "successful" response from the service with no top-level error code. Use * {@link #getErrors()} to retrieve a list of objects whose deletion failed, * along with the error code and message for each individual failure. */ @Override public String getErrorCode() { return super.getErrorCode(); }
@Override public boolean test(AmazonS3Exception exception) { if (exception == null || exception.getErrorCode() == null || exception.getErrorMessage() == null) { return false; } return exception.getErrorCode().contains(ERROR_CODE) && exception.getErrorMessage().contains(RETYABLE_ERROR_MESSAGE); } }
|| "NoSuchKey".equals(e.getErrorCode()) || "NoSuchBucket".equals(e.getErrorCode())) { return Optional.absent(); } else {
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + "; S3 Extended Request ID: " + getExtendedRequestId() + ")"; }
if (e instanceof AmazonS3Exception && ((AmazonS3Exception)e).getStatusCode() == 403 && ((AmazonS3Exception) e).getErrorCode().equals("AccessDenied")) { getLogger().warn("AccessDenied checking S3 Multipart Upload list for {}: {} " + "** The configured user does not have the s3:ListBucketMultipartUploads permission " +
/** * Always returns {@code null} since this exception represents a * "successful" response from the service with no top-level error code. Use * {@link #getErrors()} to retrieve a list of objects whose deletion failed, * along with the error code and message for each individual failure. */ @Override public String getErrorCode() { return super.getErrorCode(); }
boolean test(AmazonS3Exception exception) { if (exception == null || exception.getErrorCode() == null || exception.getErrorMessage() == null) { return false; } return exception.getErrorCode().contains(ERROR_CODE) && exception.getErrorMessage().contains(RETYABLE_ERROR_MESSAGE); } }
LOG.warn("{} Couldn't upload {} due to {} - {}", logIdentifier, file, se.getErrorCode(), se.getErrorMessage(), se); throw se; } catch (Exception e) {
/** * Always returns {@code null} since this exception represents a * "successful" response from the service with no top-level error code. Use * {@link #getErrors()} to retrieve a list of objects whose deletion failed, * along with the error code and message for each individual failure. */ @Override public String getErrorCode() { return super.getErrorCode(); }
/** * Always returns {@code null} since this exception represents a * "successful" response from the service with no top-level error code. Use * {@link #getErrors()} to retrieve a list of objects whose deletion failed, * along with the error code and message for each individual failure. */ @Override public String getErrorCode() { return super.getErrorCode(); }
@Test public void testErrorResponseFromUnparsableXML() throws IOException { String response = "<Error>" + "<Message>testError"; ByteArrayInputStream content = new ByteArrayInputStream(response.getBytes(StringUtils.UTF8)); HttpResponse errorResponse = new HttpResponse.Builder() .statusCode(200) .content(content) .statusText("testError").build(); S3ErrorResponseHandler handler = new S3ErrorResponseHandler(); AmazonS3Exception ase = (AmazonS3Exception) handler.handle(errorResponse); assertEquals(ase.getStatusCode(), 200); assertEquals(ase.getErrorType(), ErrorType.Client); assertEquals(ase.getErrorCode(), "200 testError"); }
boolean test(AmazonS3Exception exception) { if (exception == null || exception.getErrorCode() == null || exception.getErrorMessage() == null) { return false; } return exception.getErrorCode().contains(ERROR_CODE) && exception.getErrorMessage().contains(RETYABLE_ERROR_MESSAGE); } }
@Override public boolean test(AmazonS3Exception exception) { if (exception == null || exception.getErrorCode() == null || exception.getErrorMessage() == null) { return false; } return exception.getErrorCode().contains(ERROR_CODE) && exception.getErrorMessage().contains(RETYABLE_ERROR_MESSAGE); } }
private static boolean bucketAccessDenied(AmazonS3 s3, String name) { try { s3.getBucketLocation(name + UUID.randomUUID()); return false; } catch(AmazonS3Exception e) { return e.getErrorCode().equals("AccessDenied"); } } }
protected boolean shouldRetry(AmazonClientException e) { if (e instanceof AmazonS3Exception) { AmazonS3Exception s3e = (AmazonS3Exception)e; if (s3e.getStatusCode() == 400 && "RequestTimeout".equals(s3e.getErrorCode())) { return true; } } return e.isRetryable(); }
@Test public void testHandleErrorResponse() throws IOException { String response = "<Error>" + "<Message>testError</Message>" + "<Code>testCode</Code>" + "<RequestId>testId</RequestId>" + "<HostId>testHost</HostId>" + "</Error>"; ByteArrayInputStream content = new ByteArrayInputStream(response.getBytes(StringUtils.UTF8)); HttpResponse errorResponse = new HttpResponse.Builder() .statusCode(200) .content(content) .statusText("testError").build(); S3ErrorResponseHandler handler = new S3ErrorResponseHandler(); AmazonS3Exception ase = (AmazonS3Exception) handler.handle(errorResponse); assertEquals(ase.getErrorMessage(), "testError"); assertEquals(ase.getErrorType(), ErrorType.Client); assertEquals(ase.getRequestId(), "testId"); assertEquals(ase.getExtendedRequestId(), "testHost"); assertEquals(ase.getStatusCode(), 200); assertEquals(ase.getErrorCode(), "testCode"); }
@Override public FeatureState getFeatureState(Feature feature) { try (S3Object object = client.getObject(bucketName, keyPrefix + feature.name())) { if (object != null) { FeatureStateStorageWrapper wrapper = objectMapper.reader() .forType(FeatureStateStorageWrapper.class) .readValue(object.getObjectContent()); return FeatureStateStorageWrapper.featureStateForWrapper(feature, wrapper); } } catch (AmazonS3Exception ae) { if (ERR_NO_SUCH_KEY.equals(ae.getErrorCode())) { return null; } throw ae; } catch (IOException e) { throw new RuntimeException("Failed to set the feature state", e); } return null; }
class CloudFrontRetryCondition implements RetryCondition { @Override public boolean shouldRetry(AmazonWebServiceRequest originalRequest, AmazonClientException exception, int retriesAttempted) { if(exception instanceof AmazonS3Exception) { final AmazonS3Exception s3Exception = (AmazonS3Exception) exception; return s3Exception.getStatusCode() == 400 && s3Exception.getErrorCode().equals("MalformedPolicy") && s3Exception.getErrorMessage().equals("Invalid principal in policy") && s3Exception.getAdditionalDetails().get("Detail").contains("arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity"); } else { return false; } } }
/** * This method is like {@link #lockToLatest()} except that the caller requests a specific Stash time. * @throws StashNotAvailableException Thrown if no Stash is available for the given time */ public void lockToStashCreatedAt(Date creationTime) throws StashNotAvailableException { String stashDirectory = StashUtil.getStashDirectoryForCreationTime(creationTime); // The following call will raise an AmazonS3Exception if the file cannot be read try (S3Object s3Object = _s3.getObject(_bucket, String.format("%s/%s/%s", _rootPath, stashDirectory, StashUtil.SUCCESS_FILE))) { _lockedLatest = String.format("%s/%s", _rootPath, stashDirectory); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404 || // The following conditions indicate the file has already been moved to Glacier (e.getStatusCode() == 403 && "InvalidObjectState".equals(e.getErrorCode()))) { throw new StashNotAvailableException(); } throw e; } catch (IOException e) { // Shouldn't happen since the file is never actually read } }
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + "; S3 Extended Request ID: " + getExtendedRequestId() + ")"; }