use of com.example.s3objectlambda.error.S3RequestError in project amazon-s3-object-lambda-default-configuration by aws-samples.
the class GetObjectResponseHandler method writeS3GetObjectErrorResponse.
public void writeS3GetObjectErrorResponse(HttpResponse<InputStream> presignedResponse) {
S3RequestError s3errorResponse;
try {
var xmlResponse = IOUtils.toString(presignedResponse.body());
s3errorResponse = new XMLErrorParser().parse(xmlResponse);
} catch (IOException | ParserConfigurationException | SAXException | NullPointerException e) {
this.logger.error("Error while reading the S3 error response body: " + e);
writeErrorResponse("Unexpected error while reading the S3 error response", Error.SERVER_ERROR);
return;
}
this.s3Client.writeGetObjectResponse(new WriteGetObjectResponseRequest().withRequestRoute(this.event.outputRoute()).withRequestToken(this.event.outputToken()).withErrorCode(s3errorResponse.getCode()).withContentLength(0L).withInputStream(new ByteArrayInputStream(new byte[0])).withErrorMessage(s3errorResponse.getMessage()).withStatusCode(presignedResponse.statusCode()));
}
Aggregations