-
-
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`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /", {}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: