@rmdes/indiekit-endpoint-github 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -109,16 +109,16 @@ export const activityController = {
|
|
|
109
109
|
activity = utils.extractRepoActivity(events, username);
|
|
110
110
|
}
|
|
111
111
|
} catch (apiError) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.json({ error: apiError.message });
|
|
112
|
+
console.error("[Activity] API error:", apiError.message);
|
|
113
|
+
return response.json({ activity: [], error: "GitHub API temporarily unavailable" });
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
activity = activity.slice(0, limits.activity);
|
|
118
117
|
|
|
119
118
|
response.json({ activity });
|
|
120
119
|
} catch (error) {
|
|
121
|
-
|
|
120
|
+
console.error("[Activity] Controller error:", error.message);
|
|
121
|
+
response.json({ activity: [], error: "GitHub API temporarily unavailable" });
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
124
|
};
|
|
@@ -206,7 +206,16 @@ export const changelogController = {
|
|
|
206
206
|
generatedAt: new Date().toISOString(),
|
|
207
207
|
});
|
|
208
208
|
} catch (error) {
|
|
209
|
-
|
|
209
|
+
console.error("[Changelog] API error:", error.message);
|
|
210
|
+
response.json({
|
|
211
|
+
commits: [],
|
|
212
|
+
categories: {},
|
|
213
|
+
commitCategories: {},
|
|
214
|
+
totalCommits: 0,
|
|
215
|
+
days: daysValue || 30,
|
|
216
|
+
generatedAt: new Date().toISOString(),
|
|
217
|
+
error: "GitHub API temporarily unavailable",
|
|
218
|
+
});
|
|
210
219
|
}
|
|
211
220
|
},
|
|
212
221
|
};
|
package/lib/controllers/stars.js
CHANGED
|
@@ -69,16 +69,16 @@ export const starsController = {
|
|
|
69
69
|
try {
|
|
70
70
|
starred = await client.getUserStarred(username, limits.stars);
|
|
71
71
|
} catch (apiError) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.json({ error: apiError.message });
|
|
72
|
+
console.error("[Stars] API error:", apiError.message);
|
|
73
|
+
return response.json({ stars: [], error: "GitHub API temporarily unavailable" });
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
const stars = utils.formatStarred(starred);
|
|
78
77
|
|
|
79
78
|
response.json({ stars });
|
|
80
79
|
} catch (error) {
|
|
81
|
-
|
|
80
|
+
console.error("[Stars] Controller error:", error.message);
|
|
81
|
+
response.json({ stars: [], error: "GitHub API temporarily unavailable" });
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
};
|
package/lib/github-client.js
CHANGED
|
@@ -22,7 +22,7 @@ export class GitHubClient {
|
|
|
22
22
|
async fetch(endpoint) {
|
|
23
23
|
const url = `${BASE_URL}${endpoint}`;
|
|
24
24
|
|
|
25
|
-
// Check cache first
|
|
25
|
+
// Check cache first — return fresh data immediately
|
|
26
26
|
const cached = this.cache.get(url);
|
|
27
27
|
if (cached && Date.now() - cached.timestamp < this.cacheTtl) {
|
|
28
28
|
return cached.data;
|
|
@@ -37,28 +37,40 @@ export class GitHubClient {
|
|
|
37
37
|
headers.Authorization = `Bearer ${this.token}`;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
try {
|
|
41
|
+
const response = await fetch(url, { headers });
|
|
42
|
+
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
// Only use fromFetch for JSON error responses; GitHub sometimes returns
|
|
45
|
+
// HTML error pages (e.g., 502 Bad Gateway) which cause SyntaxError noise
|
|
46
|
+
const contentType = response.headers.get("content-type") || "";
|
|
47
|
+
if (contentType.includes("json")) {
|
|
48
|
+
throw await IndiekitError.fromFetch(response);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw new IndiekitError(response.statusText, {
|
|
52
|
+
status: response.status,
|
|
53
|
+
code: response.statusText,
|
|
54
|
+
});
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
status: response.status,
|
|
52
|
-
code: response.statusText,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
57
|
+
const data = await response.json();
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
// Cache result
|
|
60
|
+
this.cache.set(url, { data, timestamp: Date.now() });
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
return data;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// Stale-while-error: if we have stale cached data, return it
|
|
65
|
+
if (cached) {
|
|
66
|
+
console.warn(
|
|
67
|
+
`[GitHub] API error for ${endpoint}: ${error.message}. Serving stale cache (age: ${Math.round((Date.now() - cached.timestamp) / 60_000)}min)`,
|
|
68
|
+
);
|
|
69
|
+
return cached.data;
|
|
70
|
+
}
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
/**
|
package/package.json
CHANGED