Java Code Examples for com.amazonaws.AmazonServiceException#getErrorCode()

The following examples show how to use com.amazonaws.AmazonServiceException#getErrorCode() . 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: ExceptionHandleAwsClientWrapper.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected AutoException handleException(AmazonServiceException exception, Method method, Object[] args) {
    Object request = null;
    if (method.getParameterTypes().length > 0) {
        request = args[0];
    }

    // UserDataにはパスワードが含まれているためマスクする
    if (request instanceof RunInstancesRequest) {
        ((RunInstancesRequest) request).setUserData(null);
    }

    String str = StringUtils.reflectToString(request);

    return new AutoException("EAWS-000003", exception, method.getName(), exception.getErrorCode(),
            exception.getMessage(), str);
}
 
Example 2
Source File: AmazonServiceExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BackgroundException map(final AmazonClientException e) {
    final StringBuilder buffer = new StringBuilder();
    if(e instanceof AmazonServiceException) {
        final AmazonServiceException failure = (AmazonServiceException) e;
        this.append(buffer, failure.getErrorMessage());
        switch(failure.getStatusCode()) {
            case HttpStatus.SC_BAD_REQUEST:
                switch(failure.getErrorCode()) {
                    case "Throttling":
                        return new RetriableAccessDeniedException(buffer.toString(), e);
                    case "AccessDeniedException":
                        return new AccessDeniedException(buffer.toString(), e);
                    case "UnrecognizedClientException":
                        return new LoginFailureException(buffer.toString(), e);
                }
            case HttpStatus.SC_FORBIDDEN:
                switch(failure.getErrorCode()) {
                    case "SignatureDoesNotMatch":
                        return new LoginFailureException(buffer.toString(), e);
                    case "InvalidAccessKeyId":
                        return new LoginFailureException(buffer.toString(), e);
                    case "InvalidClientTokenId":
                        return new LoginFailureException(buffer.toString(), e);
                    case "InvalidSecurity":
                        return new LoginFailureException(buffer.toString(), e);
                    case "MissingClientTokenId":
                        return new LoginFailureException(buffer.toString(), e);
                    case "MissingAuthenticationToken":
                        return new LoginFailureException(buffer.toString(), e);
                }
        }
        return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), buffer.toString()));
    }
    this.append(buffer, e.getMessage());
    return this.wrap(e, buffer);
}
 
Example 3
Source File: S3DaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves an S3 object.
 *
 * @param s3Client the S3 client
 * @param bucketName the S3 bucket name
 * @param key the S3 object key
 * @param errorOnNoSuchKey true to throw an error when the object key is not found, otherwise return null
 *
 * @return the S3 object
 * @throws ObjectNotFoundException when specified bucket or key does not exist or access to bucket or key is denied
 */
private S3Object getS3Object(AmazonS3Client s3Client, String bucketName, String key, boolean errorOnNoSuchKey)
{
    try
    {
        GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
        return s3Operations.getS3Object(getObjectRequest, s3Client);
    }
    catch (AmazonServiceException amazonServiceException)
    {
        String errorCode = amazonServiceException.getErrorCode();

        if (S3Operations.ERROR_CODE_ACCESS_DENIED.equals(errorCode))
        {
            throw new ObjectNotFoundException(
                "Application does not have access to the specified S3 object at bucket '" + bucketName + "' and key '" + key + "'.",
                amazonServiceException);
        }
        else if (S3Operations.ERROR_CODE_NO_SUCH_BUCKET.equals(errorCode))
        {
            throw new ObjectNotFoundException("Specified S3 bucket '" + bucketName + "' does not exist.", amazonServiceException);
        }
        else if (S3Operations.ERROR_CODE_NO_SUCH_KEY.equals(errorCode))
        {
            if (errorOnNoSuchKey)
            {
                throw new ObjectNotFoundException("Specified S3 object key '" + key + "' does not exist.", amazonServiceException);
            }
            else
            {
                return null;
            }
        }
        else
        {
            throw amazonServiceException;
        }
    }
}
 
Example 4
Source File: AmazonSQSMessagingClientWrapper.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Create generic error message for <code>AmazonServiceException</code>. Message include
 * Action, RequestId, HTTPStatusCode, and AmazonErrorCode.
 */
private String logAndGetAmazonServiceException(AmazonServiceException ase, String action) {
    String errorMessage = "AmazonServiceException: " + action + ". RequestId: " + ase.getRequestId() +
                          "\nHTTPStatusCode: " + ase.getStatusCode() + " AmazonErrorCode: " +
                          ase.getErrorCode();
    LOG.error(errorMessage, ase);
    return errorMessage;
}