src/main/java/com/amazonaws/hal/client/StatusCodeErrorResponseHandler.java
public AmazonServiceException handle(HttpResponse response)
            throws Exception {
        JSONObject jsonBody = getBodyAsJson(response);
        Class<? extends AmazonServiceException> exceptionClass = exceptionClasses.get(response.getStatusCode());
        AmazonServiceException result;

        // Support other attribute names for the message?
        // TODO: Inspect exception type (caching details) and apply other values from the body
        String message = jsonBody.has("message") ? jsonBody.getString("message") : jsonBody.getString("Message");

        if (exceptionClass != null) {
            result = exceptionClass.getConstructor(String.class).newInstance(message);
        } else {
            result = AmazonServiceException.class.getConstructor(String.class).newInstance(message);
        }

        result.setServiceName(response.getRequest().getServiceName());
        result.setStatusCode(response.getStatusCode());

        if (response.getStatusCode() < 500) {
            result.setErrorType(ErrorType.Client);
        } else {
            result.setErrorType(ErrorType.Service);
        }

        for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) {
            if (headerEntry.getKey().equalsIgnoreCase("X-Amzn-RequestId")) {
                result.setRequestId(headerEntry.getValue());
            }
        }

        return result;
    }
public AmazonServiceException handle(HttpResponse response)
            throws Exception {
        JSONObject jsonBody = getBodyAsJson(response);
        Class<? extends AmazonServiceException> exceptionClass = exceptionClasses.get(response.getStatusCode());
        AmazonServiceException result;

        // Support other attribute names for the message?
        // TODO: Inspect exception type (caching details) and apply other values from the body
        String message = jsonBody.has("message") ? jsonBody.getString("message") : jsonBody.getString("Message");

        if (exceptionClass != null) {
            result = exceptionClass.getConstructor(String.class).newInstance(message);
        } else {
            result = AmazonServiceException.class.getConstructor(String.class).newInstance(message);
        }

        result.setServiceName(response.getRequest().getServiceName());
        result.setStatusCode(response.getStatusCode());

        if (response.getStatusCode() < 500) {
            result.setErrorType(ErrorType.Client);
        } else {
            result.setErrorType(ErrorType.Service);
        }

        for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) {
            if (headerEntry.getKey().equalsIgnoreCase("X-Amzn-RequestId")) {
                result.setRequestId(headerEntry.getValue());
            }
        }

        return result;
    }
-------------------------------------------------------------