refactor: use more clear retryer error messages (#3216)
This commit is contained in:
1 parent
c42798b39e
commit
976db143de
2 files changed
+10
-3
No files matched your search
@@ -1,10 +1,12 @@
|
|||||||
import { CustomError, logger } from "./utils.js";
|
import { CustomError, logger } from "./utils.js";
|
||||||
|
|
||||||
// Script variables.
|
// Script variables.
|
||||||
|
|
||||||
|
// Count the number of GitHub API tokens available.
|
||||||
const PATs = Object.keys(process.env).filter((key) =>
|
const PATs = Object.keys(process.env).filter((key) =>
|
||||||
/PAT_\d*$/.exec(key),
|
/PAT_\d*$/.exec(key),
|
||||||
).length;
|
).length;
|
||||||
const RETRIES = PATs ? PATs : 7;
|
const RETRIES = process.env.NODE_ENV === "test" ? 7 : PATs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import("axios").AxiosResponse} AxiosResponse Axios response.
|
* @typedef {import("axios").AxiosResponse} AxiosResponse Axios response.
|
||||||
@@ -20,6 +22,9 @@ const RETRIES = PATs ? PATs : 7;
|
|||||||
* @returns {Promise<T>} The response from the fetcher function.
|
* @returns {Promise<T>} The response from the fetcher function.
|
||||||
*/
|
*/
|
||||||
const retryer = async (fetcher, variables, retries = 0) => {
|
const retryer = async (fetcher, variables, retries = 0) => {
|
||||||
|
if (!RETRIES) {
|
||||||
|
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("Maximum retries exceeded", CustomError.MAX_RETRY);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -381,8 +381,9 @@ const CONSTANTS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const SECONDARY_ERROR_MESSAGES = {
|
const SECONDARY_ERROR_MESSAGES = {
|
||||||
MAX_RETRY:
|
MAX_RETRY: "Downtime due to GitHub API rate limiting",
|
||||||
"Please add an env variable called PAT_1 with your github token in vercel",
|
NO_TOKENS:
|
||||||
|
"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",
|
||||||
GRAPHQL_ERROR: "Please try again later",
|
GRAPHQL_ERROR: "Please try again later",
|
||||||
WAKATIME_USER_NOT_FOUND: "Make sure you have a public WakaTime profile",
|
WAKATIME_USER_NOT_FOUND: "Make sure you have a public WakaTime profile",
|
||||||
@@ -403,6 +404,7 @@ class CustomError extends Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static MAX_RETRY = "MAX_RETRY";
|
static MAX_RETRY = "MAX_RETRY";
|
||||||
|
static NO_TOKENS = "NO_TOKENS";
|
||||||
static USER_NOT_FOUND = "USER_NOT_FOUND";
|
static USER_NOT_FOUND = "USER_NOT_FOUND";
|
||||||
static GRAPHQL_ERROR = "GRAPHQL_ERROR";
|
static GRAPHQL_ERROR = "GRAPHQL_ERROR";
|
||||||
static WAKATIME_ERROR = "WAKATIME_ERROR";
|
static WAKATIME_ERROR = "WAKATIME_ERROR";
|
||||||
|
|||||||
Reference in new issue
Block a user