Skip to content

Instantly share code, notes, and snippets.

@nimadini
Last active August 4, 2022 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimadini/516b82ff69e374259ce23909c1a6f6da to your computer and use it in GitHub Desktop.
Save nimadini/516b82ff69e374259ce23909c1a6f6da to your computer and use it in GitHub Desktop.
An example that shows a deprecation message is printed when using `onAbuseLimit` key for `throttle`.
import {Octokit} from "octokit";
const octokit = new Octokit({
// Point the baseUrl to the dummy server that simulates a secondary rate limit error.
baseUrl: 'http://127.0.0.1:3000',
throttle: {
onRateLimit: (retryAfter, options, octokit) => {
console.log("In onRateLimit")
return true
},
onAbuseLimit: (retryAfter, options, octokit) => {
console.log("In onAbuseLimit")
return true
}
}
});
while(true) {
await octokit.request("GET /", {});
}
import http from 'http'
const hostname = '127.0.0.1';
const port = 3000;
// A dummy server to simulate a secondary rate limit error.
const server = http.createServer((req, res) => {
res.statusCode = 403;
res.setHeader("retry-after", "1");
res.setHeader("content-type", "application/json; charset=utf-8");
// @octokit/plugin-throttling.js checks for presence of 'secondary rate' in the error message.
// https://github.com/octokit/plugin-throttling.js/blob/master/src/index.ts#L133
res.write("{\"message\": \"Dummy error message that contains the keyword 'secondary rate' checked by plugin-throttling.js\"}")
res.end();
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
@nimadini
Copy link
Author

nimadini commented Aug 4, 2022

Output:

% node client.js
[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead
In onAbuseLimit
[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead
In onAbuseLimit
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment