Skip to content

Commit 0c922d8

Browse files
committed
fix: crash due to missing aperture config
1 parent 830e70e commit 0c922d8

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

network.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,37 @@ export async function makeRequest(method, url, requestOptions) {
9292
* }
9393
* */
9494
export async function makeRequestWithRateLimit(method, url, options){
95-
const flow = await getApertureClient().startFlow("external-api-request", {
95+
let flow;
96+
try {
97+
flow = await getApertureClient().startFlow("external-api", {
9698
labels: {
9799
url: url,
98100
},
99101
grpcCallOptions: {
100102
deadline: Date.now() + 300, // ms
101103
},
102104
});
103-
104-
if (flow.shouldRun()) {
105+
} catch(err){
106+
console.error("Aperture client for rate limiting is not setup correctly");
107+
console.log("Make sure to setup set correct APERTURE_SERVICE_ADDRESS and APERTURE_API_KEY in environment variables");
108+
console.log("Going to make request without rate limit");
109+
} finally {
110+
// Make request if allowed as per rate limit
111+
// In case rate limiting is not setup properly, make request anyway
112+
if (!flow || flow.shouldRun()) {
105113
// Add business logic to process incoming request
106114
console.log("Request accepted. Processing...");
107115
const {res, data} = await makeRequest(...arguments)
108116
return { res, data}
109117
} else {
110118
console.log("Request rate-limited. Try again later.");
111-
// Handle flow rejection
112-
flow.setStatus(FlowStatus.Error);
119+
if(flow) {
120+
// Handle flow rejection
121+
flow.setStatus(FlowStatus.Error);
122+
}
113123
}
114-
115124
if (flow) {
116125
flow.end();
117126
}
118-
}
127+
}
128+
}

package-lock.json

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "open-community-kit",
3-
"version": "1.1.1",
3+
"version": "1.2.1",
44
"description": "Tools and stats for open-source communities",
55
"main": "contributors.js",
66
"type": "module",
@@ -13,6 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"chai": "^4.3.10",
16+
"dotenv": "^16.3.1",
1617
"mocha": "^10.2.0",
1718
"nyc": "^15.1.0",
1819
"sinon": "^16.1.3"

test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import 'dotenv/config'
12
import { expect, assert } from "chai";
23

34
import OCK from "../index.js";
4-
55
import * as contributorsFixture from "./fixtures/contributors.fixture.js";
66

77
describe('index.js', function() {

0 commit comments

Comments
 (0)