@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
58 lines • 1.81 kB
JavaScript
/**
*
* @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.
*/
export 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.
*/
export 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.
*/
export 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