/** * Unmarshalls the XML into the appropriate modeled exception based on the error code. If the error code * is not present or does not match any known exception we unmarshall into the base service exception. * * @param errorRoot Root of <Error/> element. Contains any modeled fields of the exception. * @param errorCode Error code identifying the modeled exception. * @return Unmarshalled exception builder. */ private AwsServiceException.Builder unmarshallFromErrorCode(SdkHttpFullResponse response, XmlElement errorRoot, String errorCode) { SdkPojo sdkPojo = exceptions.stream() .filter(e -> e.errorCode().equals(errorCode)) .map(ExceptionMetadata::exceptionBuilderSupplier) .findAny() .orElse(defaultExceptionSupplier) .get(); AwsServiceException.Builder builder = ((AwsServiceException) errorUnmarshaller.unmarshall(sdkPojo, errorRoot, response)).toBuilder(); builder.message(getMessage(errorRoot)); return builder; }
/** * Unmarshalls the XML into the appropriate modeled exception based on the error code. If the error code * is not present or does not match any known exception we unmarshall into the base service exception. * * @param errorRoot Root of <Error/> element. Contains any modeled fields of the exception. * @param errorCode Error code identifying the modeled exception. * @return Unmarshalled exception builder. */ private AwsServiceException.Builder unmarshallFromErrorCode(SdkHttpFullResponse response, XmlElement errorRoot, String errorCode) { SdkPojo sdkPojo = exceptions.stream() .filter(e -> e.errorCode().equals(errorCode)) .map(ExceptionMetadata::exceptionBuilderSupplier) .findAny() .orElse(defaultExceptionSupplier) .get(); AwsServiceException.Builder builder = ((AwsServiceException) errorUnmarshaller.unmarshall(sdkPojo, errorRoot, response)).toBuilder(); builder.message(getMessage(errorRoot)); return builder; }
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)); // Status code and request id are sdk level fields exception.message(errorMessage); exception.statusCode(statusCode(response, modeledExceptionMetadata)); exception.requestId(getRequestIdFromHeaders(response.headers())); return exception.build(); }
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)); // Status code and request id are sdk level fields exception.message(errorMessage); exception.statusCode(statusCode(response, modeledExceptionMetadata)); exception.requestId(getRequestIdFromHeaders(response.headers())); return exception.build(); }