Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fd1ea3

Browse files
feature: do not aks user's to open issues on upstream API errors (anuraghazra#3273)
Co-authored-by: rickstaa <rick.staa@outlook.com>
1 parenta397851 commit0fd1ea3

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

‎src/common/utils.js‎

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@ import toEmoji from "emoji-name-map";
44
importwrapfrom"word-wrap";
55
import{themes}from"../../themes/index.js";
66

7+
constTRY_AGAIN_LATER="Please try again later";
8+
9+
constSECONDARY_ERROR_MESSAGES={
10+
MAX_RETRY:
11+
"You can deploy own instance or wait until public will be no longer limited",
12+
NO_TOKENS:
13+
"Please add an env variable called PAT_1 with your GitHub API token in vercel",
14+
USER_NOT_FOUND:"Make sure the provided username is not an organization",
15+
GRAPHQL_ERROR:TRY_AGAIN_LATER,
16+
GITHUB_REST_API_ERROR:TRY_AGAIN_LATER,
17+
WAKATIME_USER_NOT_FOUND:"Make sure you have a public WakaTime profile",
18+
};
19+
20+
/**
21+
* Custom error class to handle custom GRS errors.
22+
*/
23+
classCustomErrorextendsError{
24+
/**
25+
*@param {string} message Error message.
26+
*@param {string} type Error type.
27+
*/
28+
constructor(message,type){
29+
super(message);
30+
this.type=type;
31+
this.secondaryMessage=SECONDARY_ERROR_MESSAGES[type]||type;
32+
}
33+
34+
staticMAX_RETRY="MAX_RETRY";
35+
staticNO_TOKENS="NO_TOKENS";
36+
staticUSER_NOT_FOUND="USER_NOT_FOUND";
37+
staticGRAPHQL_ERROR="GRAPHQL_ERROR";
38+
staticGITHUB_REST_API_ERROR="GITHUB_REST_API_ERROR";
39+
staticWAKATIME_ERROR="WAKATIME_ERROR";
40+
}
41+
742
// Script parameters.
843
constERROR_CARD_LENGTH=576.5;
944

@@ -23,6 +58,11 @@ const encodeHTML = (str) => {
2358
.replace(/\u0008/gim,"");
2459
};
2560

61+
constUPSTREAM_API_ERRORS=[
62+
TRY_AGAIN_LATER,
63+
SECONDARY_ERROR_MESSAGES.MAX_RETRY,
64+
];
65+
2666
/**
2767
* Renders error message on the card.
2868
*
@@ -41,7 +81,11 @@ const renderError = (message, secondaryMessage = "") => {
4181
<rect x="0.5" y="0.5" width="${
4282
ERROR_CARD_LENGTH-1
4383
}" height="99%" rx="4.5" fill="#FFFEFE" stroke="#E4E2E2"/>
44-
<text x="25" y="45" class="text">Something went wrong! file an issue at https://tiny.one/readme-stats</text>
84+
<text x="25" y="45" class="text">Something went wrong!${
85+
UPSTREAM_API_ERRORS.includes(secondaryMessage)
86+
?""
87+
:" file an issue at https://tiny.one/readme-stats"
88+
}</text>
4589
<text data-testid="message" x="25" y="55" class="text small">
4690
<tspan x="25" dy="18">${encodeHTML(message)}</tspan>
4791
<tspan x="25" dy="18" class="gray">${secondaryMessage}</tspan>
@@ -399,41 +443,6 @@ const CONSTANTS = {
399443
ERROR_CACHE_SECONDS:TEN_MINUTES,
400444
};
401445

402-
constTRY_AGAIN_LATER="Please try again later";
403-
404-
constSECONDARY_ERROR_MESSAGES={
405-
MAX_RETRY:
406-
"You can deploy own instance or wait until public will be no longer limited",
407-
NO_TOKENS:
408-
"Please add an env variable called PAT_1 with your GitHub API token in vercel",
409-
USER_NOT_FOUND:"Make sure the provided username is not an organization",
410-
GRAPHQL_ERROR:TRY_AGAIN_LATER,
411-
GITHUB_REST_API_ERROR:TRY_AGAIN_LATER,
412-
WAKATIME_USER_NOT_FOUND:"Make sure you have a public WakaTime profile",
413-
};
414-
415-
/**
416-
* Custom error class to handle custom GRS errors.
417-
*/
418-
classCustomErrorextendsError{
419-
/**
420-
*@param {string} message Error message.
421-
*@param {string} type Error type.
422-
*/
423-
constructor(message,type){
424-
super(message);
425-
this.type=type;
426-
this.secondaryMessage=SECONDARY_ERROR_MESSAGES[type]||type;
427-
}
428-
429-
staticMAX_RETRY="MAX_RETRY";
430-
staticNO_TOKENS="NO_TOKENS";
431-
staticUSER_NOT_FOUND="USER_NOT_FOUND";
432-
staticGRAPHQL_ERROR="GRAPHQL_ERROR";
433-
staticGITHUB_REST_API_ERROR="GITHUB_REST_API_ERROR";
434-
staticWAKATIME_ERROR="WAKATIME_ERROR";
435-
}
436-
437446
/**
438447
* Missing query parameter class.
439448
*/

‎tests/api.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,9 @@ describe("Test /api/", () => {
321321
expect(res.send).toBeCalledWith(
322322
renderError("Could not fetch total commits.","Please try again later"),
323323
);
324+
// Received SVG output should not contain string "https://tiny.one/readme-stats"
325+
expect(res.send.mock.calls[0][0]).not.toContain(
326+
"https://tiny.one/readme-stats",
327+
);
324328
});
325329
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp