refactor: use more clear retryer error message (2) (#3227)

This commit is contained in:
Alexandr Garbuzov 2023-09-14 11:47:00 +03:00 committed by GitHub
parent 81f030fd1c
commit ef0ec6e26b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -26,7 +26,10 @@ const retryer = async (fetcher, variables, retries = 0) => {
throw new CustomError("No GitHub API tokens found", CustomError.NO_TOKENS); throw new CustomError("No GitHub API tokens found", CustomError.NO_TOKENS);
} }
if (retries > RETRIES) { if (retries > RETRIES) {
throw new CustomError("Maximum retries exceeded", CustomError.MAX_RETRY); throw new CustomError(
"Downtime due to GitHub API rate limiting",
CustomError.MAX_RETRY,
);
} }
try { try {
// try to fetch with the first token since RETRIES is 0 index i'm adding +1 // try to fetch with the first token since RETRIES is 0 index i'm adding +1

View File

@ -381,7 +381,8 @@ const CONSTANTS = {
}; };
const SECONDARY_ERROR_MESSAGES = { const SECONDARY_ERROR_MESSAGES = {
MAX_RETRY: "Downtime due to GitHub API rate limiting", MAX_RETRY:
"You can deploy own instance or wait until public will be no longer limited",
NO_TOKENS: NO_TOKENS:
"Please add an env variable called PAT_1 with your GitHub API token in vercel", "Please add an env variable called PAT_1 with your GitHub API token in vercel",
USER_NOT_FOUND: "Make sure the provided username is not an organization", USER_NOT_FOUND: "Make sure the provided username is not an organization",

View File

@ -40,12 +40,12 @@ describe("Test Retryer", () => {
expect(res).toStrictEqual({ data: "ok" }); expect(res).toStrictEqual({ data: "ok" });
}); });
it("retryer should throw error if maximum retries reached", async () => { it("retryer should throw specific error if maximum retries reached", async () => {
try { try {
await retryer(fetcherFail, {}); await retryer(fetcherFail, {});
} catch (err) { } catch (err) {
expect(fetcherFail).toBeCalledTimes(8); expect(fetcherFail).toBeCalledTimes(8);
expect(err.message).toBe("Maximum retries exceeded"); expect(err.message).toBe("Downtime due to GitHub API rate limiting");
} }
}); });
}); });