@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(); }
@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(); }
/** * 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(); }