@@ -4,6 +4,41 @@ import toEmoji from "emoji-name-map";
4
4
import wrap from "word-wrap" ;
5
5
import { themes } from "../../themes/index.js" ;
6
6
7
+ const TRY_AGAIN_LATER = "Please try again later" ;
8
+
9
+ const SECONDARY_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
+ class CustomError extends Error {
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
+ static MAX_RETRY = "MAX_RETRY" ;
35
+ static NO_TOKENS = "NO_TOKENS" ;
36
+ static USER_NOT_FOUND = "USER_NOT_FOUND" ;
37
+ static GRAPHQL_ERROR = "GRAPHQL_ERROR" ;
38
+ static GITHUB_REST_API_ERROR = "GITHUB_REST_API_ERROR" ;
39
+ static WAKATIME_ERROR = "WAKATIME_ERROR" ;
40
+ }
41
+
7
42
// Script parameters.
8
43
const ERROR_CARD_LENGTH = 576.5 ;
9
44
@@ -23,6 +58,11 @@ const encodeHTML = (str) => {
23
58
. replace ( / \u0008 / gim, "" ) ;
24
59
} ;
25
60
61
+ const UPSTREAM_API_ERRORS = [
62
+ TRY_AGAIN_LATER ,
63
+ SECONDARY_ERROR_MESSAGES . MAX_RETRY ,
64
+ ] ;
65
+
26
66
/**
27
67
* Renders error message on the card.
28
68
*
@@ -41,7 +81,11 @@ const renderError = (message, secondaryMessage = "") => {
41
81
<rect x="0.5" y="0.5" width="${
42
82
ERROR_CARD_LENGTH - 1
43
83
} " 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>
45
89
<text data-testid="message" x="25" y="55" class="text small">
46
90
<tspan x="25" dy="18">${ encodeHTML ( message ) } </tspan>
47
91
<tspan x="25" dy="18" class="gray">${ secondaryMessage } </tspan>
@@ -399,41 +443,6 @@ const CONSTANTS = {
399
443
ERROR_CACHE_SECONDS :TEN_MINUTES ,
400
444
} ;
401
445
402
- const TRY_AGAIN_LATER = "Please try again later" ;
403
-
404
- const SECONDARY_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
- class CustomError extends Error {
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
- static MAX_RETRY = "MAX_RETRY" ;
430
- static NO_TOKENS = "NO_TOKENS" ;
431
- static USER_NOT_FOUND = "USER_NOT_FOUND" ;
432
- static GRAPHQL_ERROR = "GRAPHQL_ERROR" ;
433
- static GITHUB_REST_API_ERROR = "GITHUB_REST_API_ERROR" ;
434
- static WAKATIME_ERROR = "WAKATIME_ERROR" ;
435
- }
436
-
437
446
/**
438
447
* Missing query parameter class.
439
448
*/