@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
63 lines • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runAndCatch404 = runAndCatch404;
exports.runAndCatchAccessDenied = runAndCatchAccessDenied;
exports.runAndCatchError = runAndCatchError;
/**
*
* @param operation The operation to run.
* @returns If successful, returns the result of operation. If operation returns a 404, returns undefined.
* @throws If operation returns a non 404 error, rethrows that error.
*/
async function runAndCatch404(operation) {
try {
const result = await operation();
return result;
}
catch (e) {
if (e['$metadata']?.httpStatusCode == 404) {
return undefined;
}
throw e;
}
}
/**
*
* @param operation The operation to run.
* @returns If successful, returns the result of operation. If operation returns a 404, returns undefined.
* @throws If operation returns a non 400 error, rethrows that error.
*/
async function runAndCatchAccessDenied(operation) {
try {
const result = await operation();
return result;
}
catch (e) {
const errorName = e.name;
if (errorName == 'AccessDeniedException' || errorName == 'AccessDenied') {
return undefined;
}
throw e;
}
}
/**
* Run an operation and catch a specific error by name. Return undefined if the error matches, otherwise rethrow the error.
*
* @param errorName the name of the error to catch
* @param operation the operation to run
* @returns If successful, returns the result of operation. If operation throws an error with the specified name, returns undefined.
* @throws If operation throws an error with a different name, rethrows that error.
*/
async function runAndCatchError(errorName, operation) {
try {
const result = await operation();
return result;
}
catch (e) {
if (e.name == errorName) {
return undefined;
}
throw e;
}
}
//# sourceMappingURL=client-tools.js.map