MCPcopy Index your code
hub / github.com/utterance/utterances / processRateLimit

Function processRateLimit

src/github.ts:50–70  ·  view source on GitHub ↗
(response: Response)

Source from the content-addressed store, hash-verified

48};
49
50function processRateLimit(response: Response) {
51 const limit = response.headers.get('X-RateLimit-Limit')!;
52 const remaining = response.headers.get('X-RateLimit-Remaining')!;
53 const reset = response.headers.get('X-RateLimit-Reset')!;
54
55 const isSearch = /\/search\//.test(response.url);
56 const rate = isSearch ? rateLimit.search : rateLimit.standard;
57
58 rate.limit = +limit;
59 rate.remaining = +remaining;
60 rate.reset = +reset;
61
62 if (response.status === 403 && rate.remaining === 0) {
63 const resetDate = new Date(0);
64 resetDate.setUTCSeconds(rate.reset);
65 const mins = Math.round((resetDate.getTime() - new Date().getTime()) / 1000 / 60);
66 const apiType = isSearch ? 'search API' : 'non-search APIs';
67 // tslint:disable-next-line:no-console
68 console.warn(`Rate limit exceeded for ${apiType}. Resets in ${mins} minute${mins === 1 ? '' : 's'}.`);
69 }
70}
71
72export function readRelNext(response: Response) {
73 const link = response.headers.get('link');

Callers 1

githubFetchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected