This repository has been archived on 2024-09-11. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs-blog-newsletter/cronjob/node_modules/@smithy/property-provider/dist-es/chain.js

22 lines
579 B
JavaScript
Raw Normal View History

2024-05-26 22:54:55 +02:00
import { ProviderError } from "./ProviderError";
export const chain = (...providers) => async () => {
if (providers.length === 0) {
throw new ProviderError("No providers in chain");
}
let lastProviderError;
for (const provider of providers) {
try {
const credentials = await provider();
return credentials;
}
catch (err) {
lastProviderError = err;
if (err?.tryNextLink) {
continue;
}
throw err;
}
}
throw lastProviderError;
};