Search in sources :

Example 1 with ExceptionMetadata

use of software.amazon.awssdk.protocols.core.ExceptionMetadata in project aws-sdk-java-v2 by aws.

the class AwsJsonProtocolErrorUnmarshaller method unmarshall.

private AwsServiceException unmarshall(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) {
    JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory);
    String errorCode = errorCodeParser.parseErrorCode(response, jsonContent);
    Optional<ExceptionMetadata> modeledExceptionMetadata = exceptions.stream().filter(e -> e.errorCode().equals(errorCode)).findAny();
    SdkPojo sdkPojo = modeledExceptionMetadata.map(ExceptionMetadata::exceptionBuilderSupplier).orElse(defaultExceptionSupplier).get();
    AwsServiceException.Builder exception = ((AwsServiceException) jsonProtocolUnmarshaller.unmarshall(sdkPojo, response, jsonContent.getJsonNode())).toBuilder();
    String errorMessage = errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode());
    exception.awsErrorDetails(extractAwsErrorDetails(response, executionAttributes, jsonContent, errorCode, errorMessage));
    exception.clockSkew(getClockSkew(executionAttributes));
    // Status code and request id are sdk level fields
    exception.message(errorMessage);
    exception.statusCode(statusCode(response, modeledExceptionMetadata));
    exception.requestId(getRequestIdFromHeaders(response.headers()));
    exception.extendedRequestId(getExtendedRequestIdFromHeaders(response.headers()));
    return exception.build();
}
Also used : ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) SdkExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkExecutionAttribute) SdkHttpUtils(software.amazon.awssdk.utils.http.SdkHttpUtils) Supplier(java.util.function.Supplier) SdkBytes(software.amazon.awssdk.core.SdkBytes) List(java.util.List) Duration(java.time.Duration) Map(java.util.Map) AwsErrorDetails(software.amazon.awssdk.awscore.exception.AwsErrorDetails) SdkPojo(software.amazon.awssdk.core.SdkPojo) Optional(java.util.Optional) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) JsonContent(software.amazon.awssdk.protocols.json.JsonContent) JsonFactory(software.amazon.awssdk.thirdparty.jackson.core.JsonFactory) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) ErrorCodeParser(software.amazon.awssdk.protocols.json.ErrorCodeParser) ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) JsonContent(software.amazon.awssdk.protocols.json.JsonContent) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) SdkPojo(software.amazon.awssdk.core.SdkPojo)

Aggregations

Duration (java.time.Duration)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)1 AwsErrorDetails (software.amazon.awssdk.awscore.exception.AwsErrorDetails)1 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 SdkPojo (software.amazon.awssdk.core.SdkPojo)1 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)1 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)1 SdkExecutionAttribute (software.amazon.awssdk.core.interceptor.SdkExecutionAttribute)1 SdkHttpFullResponse (software.amazon.awssdk.http.SdkHttpFullResponse)1 ExceptionMetadata (software.amazon.awssdk.protocols.core.ExceptionMetadata)1 ErrorCodeParser (software.amazon.awssdk.protocols.json.ErrorCodeParser)1 JsonContent (software.amazon.awssdk.protocols.json.JsonContent)1 JsonFactory (software.amazon.awssdk.thirdparty.jackson.core.JsonFactory)1 SdkHttpUtils (software.amazon.awssdk.utils.http.SdkHttpUtils)1