Skip to content

Commit 480af35

Browse files
committed
1. fails the build if it gets an rate limiting API from the data source.
2. Adds cache plugin to keep the `.cache` folder around to reduce API requests.
1 parent e5b7ce3 commit 480af35

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

netlify.toml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
status = 404
3838

3939

40+
[[plugins]]
41+
package = "./plugins/keep-dot-cache-folder"
4042

4143
# Config for the Netlify Build Plugin: netlify-plugin-minify-html
4244
[[plugins]]
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
// Restore file/directory cached in previous builds.
3+
// Does not do anything if:
4+
// - the file/directory already exists locally
5+
// - the file/directory has not been cached yet
6+
async onPreBuild({ utils }) {
7+
await utils.cache.restore('./.cache');
8+
},
9+
// Cache file/directory for future builds.
10+
// Does not do anything if:
11+
// - the file/directory does not exist locally
12+
async onPostBuild({ utils }) {
13+
await utils.cache.save('./.cache');
14+
}
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: keep-dot-cache-folder

src/site/_data/github.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ async function githubRequest(user, repo) {
6969
try {
7070
req = await CacheAsset(url, opts);
7171
if(req.errors && req.errors.length) {
72-
console.log( "Error", req.errors );
72+
console.log( "GitHub Data Source Error from API", req.errors );
73+
if(req.errors.filter(e => e.type === "RATE_LIMITED").length > 0) {
74+
throw new Error("Failing the build due to GitHub API rate limiting.");
75+
}
7376
return errorData;
7477
}
7578

@@ -79,7 +82,8 @@ async function githubRequest(user, repo) {
7982
issues: req.data.repository.issues.totalCount,
8083
}
8184
} catch(e) {
82-
console.log( "Error", e );
85+
console.log( "GitHub Data Source Error", e );
86+
8387
return errorData;
8488
}
8589
}

0 commit comments

Comments
 (0)