Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws;

Extension of AmazonClientException that represents an error response returned by an Amazon web service. Receiving an exception of this type indicates that the caller's request was correctly transmitted to the service, but for some reason, the service was not able to process it, and returned an error response instead.

AmazonServiceException provides callers several pieces of information that can be used to obtain more information about the error and why it occurred. In particular, the errorType field can be used to determine if the caller's request was invalid, or the service encountered an error on the server side while processing it.

 
 public class AmazonServiceException extends AmazonClientException {
     private static final long serialVersionUID = 1L;

    
Indicates who is responsible (if known) for a failed request.

For example, if a client is using an invalid AWS access key, the returned exception will indicate that there is an error in the request the caller is sending. Retrying that same request will *not* result in a successful response. The Client ErrorType indicates that there is a problem in the request the user is sending (ex: incorrect access keys, invalid parameter value, missing parameter, etc.), and that the caller must take some action to correct the request before it should be resent. Client errors are typically associated an HTTP error code in the 4xx range.

The Service ErrorType indicates that although the request the caller sent was valid, the service was unable to fulfill the request because of problems on the service's side. These types of errors can be retried by the caller since the caller's request was valid and the problem occurred while processing the request on the service side. Service errors will be accompanied by an HTTP error code in the 5xx range.

Finally, if there isn't enough information to determine who's fault the error response is, an Unknown ErrorType will be set.

 
     public enum ErrorType {
         Client,
         Service,
         Unknown
     }

    
The unique AWS identifier for the service request the caller made. The AWS request ID can uniquely identify the AWS request, and is used for reporting an error to AWS support team.
 
     private String requestId;

    
The AWS error code represented by this exception (ex: InvalidParameterValue).
 
     private String errorCode;

    
Indicates (if known) whether this exception was the fault of the caller or the service.

 
     private ErrorType errorType = .;

    
The error message as returned by the service.
 
     private final String errorMessage;

    
The HTTP status code that was returned with this error
 
     private int statusCode;

    
The name of the Amazon service that sent this error response.
 
     private String serviceName;

    
The raw response content as a string
 
    private String rawResponseContent;

    
Constructs a new AmazonServiceException with the specified message.

Parameters:
errorMessage An error message describing what went wrong.
    public AmazonServiceException(String errorMessage) {
        super((String)null);
        this. = errorMessage;
    }

    
Constructs a new AmazonServiceException with the specified message and exception indicating the root cause.

Parameters:
errorMessage An error message describing what went wrong.
cause The root exception that caused this exception to be thrown.
    public AmazonServiceException(String errorMessageException cause) {
        super(nullcause);
        this. = errorMessage;
    }

    
Sets the AWS requestId for this exception.

Parameters:
requestId The unique identifier for the service request the caller made.
    public void setRequestId(String requestId) {
        this. = requestId;
    }

    
Returns the AWS request ID that uniquely identifies the service request the caller made.

Returns:
The AWS request ID that uniquely identifies the service request the caller made.
    public String getRequestId() {
        return ;
    }

    
Sets the name of the service that sent this error response.

Parameters:
serviceName The name of the service that sent this error response.
    public void setServiceName(String serviceName) {
        this. = serviceName;
    }

    
Returns the name of the service that sent this error response.

Returns:
The name of the service that sent this error response.
    public String getServiceName() {
        return ;
    }

    
Sets the AWS error code represented by this exception.

Parameters:
errorCode The AWS error code represented by this exception.
    public void setErrorCode(String errorCode) {
        this. = errorCode;
    }

    
Returns the AWS error code represented by this exception.

Returns:
The AWS error code represented by this exception.
    public String getErrorCode() {
        return ;
    }

    
Sets the type of error represented by this exception (sender, receiver, or unknown), indicating if this exception was the caller's fault, or the service's fault.

Parameters:
errorType The type of error represented by this exception (sender or receiver), indicating if this exception was the caller's fault or the service's fault.
    public void setErrorType(ErrorType errorType) {
        this. = errorType;
    }

    
Indicates who is responsible for this exception (caller, service, or unknown).

Returns:
A value indicating who is responsible for this exception (caller, service, or unknown).
    public ErrorType getErrorType() {
        return ;
    }

    

Returns:
the human-readable error message provided by the service
    public String getErrorMessage() {
        return ;
    }

    
Sets the HTTP status code that was returned with this service exception.

Parameters:
statusCode The HTTP status code that was returned with this service exception.
    public void setStatusCode(int statusCode) {
        this. = statusCode;
    }

    
Returns the HTTP status code that was returned with this service exception.

Returns:
The HTTP status code that was returned with this service exception.
    public int getStatusCode() {
        return ;
    }
    @Override
    public String getMessage() {
        return getErrorMessage()
            + " (Service: " + getServiceName()
            + "; Status Code: " + getStatusCode()
            + "; Error Code: " + getErrorCode()
            + "; Request ID: " + getRequestId() + ")";
    }

    
Typically only useful for debugging purpose if for some reason the SDK cannot parse the HTTP response from a service

Returns:
The raw content of the HTTP response
    public String getRawResponseContent() {
        return ;
    }

    

Parameters:
rawResponseContent The raw content of the HTTP response
    public void setRawResponseContent(String rawResponseContent) {
        this. = rawResponseContent;
    }
New to GrepCode? Check out our FAQ X