@samitouri / QOSami-HFS / commits / 0fb3b651

admin/plugins: show a better message when github quota is reached

Massimo Melina committed May 28, 2023 at 17:01 UTC 0fb3b651cfc448a51e06d78669eb42486f8f87ea
2 files changed +18 -10
admin/src/InstalledPlugins.ts
+2 -1
@@ -142,7 +142,8 @@ const type2comp = {
142
143 export function showError(error: any) {
144 return h(Alert, { severity: 'error' }, xlate(error, {
145 - ENOTFOUND: "Couldn't reach github.com"
145 + github_quota: "Request denied. You may have reached the limit, retry later.",
146 + ENOTFOUND: "Couldn't reach github.com",
147 }))
148 }
149
src/github.ts
+16 -9
@@ -76,15 +76,22 @@ export function getFolder2repo() {
76 }
77
78 async function apiGithub(uri: string) {
79 - const res = await httpsString('https://api.github.com/'+uri, {
80 - headers: {
81 - 'User-Agent': 'HFS',
82 - Accept: 'application/vnd.github.v3+json',
83 - }
84 - })
85 - if (!res.ok)
86 - throw res.statusCode
87 - return JSON.parse(res.body)
79 + try {
80 + const res = await httpsString('https://api.github.com/'+uri, {
81 + headers: {
82 + 'User-Agent': 'HFS',
83 + Accept: 'application/vnd.github.v3+json',
84 + }
85 + })
86 + if (!res.ok)
87 + throw res.statusCode
88 + return JSON.parse(res.body)
89 + }
90 + catch(e: any) {
91 + // https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting
92 + throw e.message === '403' ? Error('github_quota')
93 + : e
94 + }
95 }
96
97 export async function* searchPlugins(text='') {