/** * @return {@link AwsErrorDetails.Builder} instance to construct a new {@link AwsErrorDetails}. */ public static Builder builder() { return new BuilderImpl(); }
@Override public AwsErrorDetails build() { return new AwsErrorDetails(this); } }
@Override public AwsServiceException build() { return new AwsServiceException(this); } }
@Override public AwsServiceException handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) { Pair<XmlElement, SdkBytes> xmlAndBytes = parseXml(response); XmlElement document = xmlAndBytes.left(); Optional<XmlElement> errorRoot = errorRootExtractor.apply(document); String errorCode = getErrorCode(errorRoot); AwsServiceException.Builder builder = errorRoot .map(e -> invokeSafely(() -> unmarshallFromErrorCode(response, e, errorCode))) .orElseGet(this::defaultException); AwsErrorDetails awsErrorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .errorMessage(builder.message()) .rawResponse(xmlAndBytes.right()) .sdkHttpResponse(response) .serviceName(executionAttributes.getAttribute(AwsExecutionAttribute.SERVICE_NAME)) .build(); builder.requestId(getRequestId(response, document)) .statusCode(response.statusCode()) .awsErrorDetails(awsErrorDetails); return builder.build(); }
/** * Build the {@link AwsErrorDetails} from the metadata in the response. * * @param response HTTP response. * @param executionAttributes Execution attributes. * @param jsonContent Parsed JSON content. * @param errorCode Parsed error code/type. * @param errorMessage Parsed error message. * @return AwsErrorDetails */ private AwsErrorDetails extractAwsErrorDetails(SdkHttpFullResponse response, ExecutionAttributes executionAttributes, JsonContent jsonContent, String errorCode, String errorMessage) { AwsErrorDetails.Builder errorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .serviceName(executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME)) .sdkHttpResponse(response); if (jsonContent.getRawContent() != null) { errorDetails.rawResponse(SdkBytes.fromByteArray(jsonContent.getRawContent())); } errorDetails.errorMessage(errorMessage); return errorDetails.build(); }
protected AwsErrorDetails(Builder b) { this.errorMessage = b.errorMessage(); this.errorCode = b.errorCode(); this.serviceName = b.serviceName(); this.sdkHttpResponse = b.sdkHttpResponse(); this.rawResponse = b.rawResponse(); }
private AwsErrorDetails fillErrorDetails(AwsErrorDetails original, String errorCode, String errorMessage) { return original.toBuilder().errorMessage(errorMessage).errorCode(errorCode).build(); }
private BuilderImpl(AwsErrorDetails awsErrorDetails) { this.errorMessage = awsErrorDetails.errorMessage(); this.errorCode = awsErrorDetails.errorCode(); this.serviceName = awsErrorDetails.serviceName(); this.sdkHttpResponse = awsErrorDetails.sdkHttpResponse(); this.rawResponse = awsErrorDetails.rawResponse(); }
@Override public String getMessage() { if (awsErrorDetails != null) { return awsErrorDetails().errorMessage() + " (Service: " + awsErrorDetails().serviceName() + ", Status Code: " + statusCode() + ", Request ID: " + requestId() + ")"; } return super.getMessage(); }
@Override public boolean shouldRetry(RetryPolicyContext context) { Exception ex = context.exception(); if (ex instanceof AwsServiceException) { AwsServiceException exception = (AwsServiceException) ex; return retryableErrorCodes.contains(exception.awsErrorDetails().errorCode()); } return false; }
protected AwsServiceException(Builder b) { super(b); this.awsErrorDetails = b.awsErrorDetails(); }
@Override public boolean isClockSkewException() { return Optional.ofNullable(awsErrorDetails) .map(a -> AwsErrorCode.CLOCK_SKEW_ERROR_CODES.contains(a.errorCode())) .orElse(false); }
protected BuilderImpl(AwsServiceException ex) { super(ex); this.awsErrorDetails = ex.awsErrorDetails(); }
/** * @return {@link Builder} instance to construct a new {@link AwsServiceException}. */ public static Builder builder() { return new BuilderImpl(); }
public void failedApiCall() { logger.info("stubing failed api call for {} protocol", protocol); mockHttpClient.stubNextResponse(errorResponse(protocol)); try { runnable().run(); } catch (AwsServiceException e) { logger.info("Received expected service exception", e.getMessage()); } mockHttpClient.reset(); }
@Override public AwsServiceException handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) { Pair<XmlElement, SdkBytes> xmlAndBytes = parseXml(response); XmlElement document = xmlAndBytes.left(); Optional<XmlElement> errorRoot = errorRootExtractor.apply(document); String errorCode = getErrorCode(errorRoot); AwsServiceException.Builder builder = errorRoot .map(e -> invokeSafely(() -> unmarshallFromErrorCode(response, e, errorCode))) .orElseGet(this::defaultException); AwsErrorDetails awsErrorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .errorMessage(builder.message()) .rawResponse(xmlAndBytes.right()) .sdkHttpResponse(response) .serviceName(executionAttributes.getAttribute(AwsExecutionAttribute.SERVICE_NAME)) .build(); builder.requestId(getRequestId(response, document)) .statusCode(response.statusCode()) .awsErrorDetails(awsErrorDetails); return builder.build(); }
/** * Build the {@link AwsErrorDetails} from the metadata in the response. * * @param response HTTP response. * @param executionAttributes Execution attributes. * @param jsonContent Parsed JSON content. * @param errorCode Parsed error code/type. * @param errorMessage Parsed error message. * @return AwsErrorDetails */ private AwsErrorDetails extractAwsErrorDetails(SdkHttpFullResponse response, ExecutionAttributes executionAttributes, JsonContent jsonContent, String errorCode, String errorMessage) { AwsErrorDetails.Builder errorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .serviceName(executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME)) .sdkHttpResponse(response); if (jsonContent.getRawContent() != null) { errorDetails.rawResponse(SdkBytes.fromByteArray(jsonContent.getRawContent())); } errorDetails.errorMessage(errorMessage); return errorDetails.build(); }
@Override public boolean isThrottlingException() { return super.isThrottlingException() || Optional.ofNullable(awsErrorDetails) .map(a -> AwsErrorCode.THROTTLING_ERROR_CODES.contains(a.errorCode())) .orElse(false); }
/** * Create a {@link AwsErrorDetails.Builder} initialized with the properties of this {@code AwsErrorDetails}. * * @return A new builder initialized with this config's properties. */ public Builder toBuilder() { return new BuilderImpl(this); }
/** * Create a {@link AwsServiceException.Builder} initialized with the properties of this {@code AwsServiceException}. * * @return A new builder initialized with this config's properties. */ @Override public Builder toBuilder() { return new BuilderImpl(this); }