Skip to content

Commit

Permalink
fix: restructured the code to throw retryable code everytime in case …
Browse files Browse the repository at this point in the history
…of unexpected error
  • Loading branch information
abhimanyubabbar committed Jun 13, 2024
1 parent 1eb1e7f commit 33f51ba
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/util/openfaas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,15 @@ const executeFaasFunction = async (
return await invokeFunction(name, events);
} catch (error) {
logger.error(`Error while invoking ${name}: ${error.message}`);
errorRaised = error;

errorRaised = error;
if (error.statusCode === 404 && error.message.includes(`error finding function ${name}`)) {
removeFunctionFromCache(name);

await setupFaasFunction(name, null, versionId, libraryVersionIDs, testMode, trMetadata);
throw new RetryRequestError(`${name} not found`);
}

if (gatewayRetriableStatus.includes(error.statusCode)) {
if (error.statusCode === 429) {
throw new RetryRequestError(`Rate limit exceeded for ${name}`);
}

throw new RetryRequestError(error.message);
}

throw error;
// all unexpected errors are retried at caller
throw new RetryRequestError(error.message);
} finally {
// delete the function created, if it's called as part of testMode
if (testMode) {
Expand Down

0 comments on commit 33f51ba

Please sign in to comment.