@infrascan/aws-s3-scanner
Version:
Infrascan scanner definition for AWS S3
57 lines (56 loc) • 1.38 kB
JavaScript
// src/middleware.ts
import {
S3ServiceException
} from "@aws-sdk/client-s3";
function isRichError(err) {
return err.Code != null;
}
function mapNotFoundErrorToEmptyResponse(context, err) {
const isRichS3Err = err instanceof S3ServiceException && isRichError(err);
if (!isRichS3Err) {
return void 0;
}
if (context.commandName === "GetBucketTaggingCommand" && err.Code === "NoSuchTagSet") {
return {
output: {
$metadata: {},
TagSet: []
},
response: err
};
}
if (context.commandName === "GetBucketWebsiteCommand" && err.Code === "NoSuchWebsiteConfiguration") {
return {
output: {
$metadata: {}
},
response: err
};
}
return void 0;
}
function ignoreS3ConfigNotFoundMiddleware(next, context) {
return async function mapNotFoundErrors(args) {
try {
return await next(args);
} catch (err) {
const mappedResponse = mapNotFoundErrorToEmptyResponse(context, err);
if (mappedResponse != null) {
return mappedResponse;
}
throw err;
}
};
}
function registerMiddleware(client) {
client.middlewareStack.add(ignoreS3ConfigNotFoundMiddleware, {
step: "finalizeRequest",
name: "ignoreS3ConfigNotFoundErrors",
tags: ["ErrorHandling"],
priority: "high"
});
}
export {
mapNotFoundErrorToEmptyResponse,
registerMiddleware
};