First upload version 0.0.1
This commit is contained in:
34
node_modules/@octokit/plugin-retry/dist-src/wrap-request.js
generated
vendored
Normal file
34
node_modules/@octokit/plugin-retry/dist-src/wrap-request.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import Bottleneck from "bottleneck/light.js";
|
||||
import { RequestError } from "@octokit/request-error";
|
||||
import { errorRequest } from "./error-request.js";
|
||||
async function wrapRequest(state, octokit, request, options) {
|
||||
const limiter = new Bottleneck();
|
||||
limiter.on("failed", function(error, info) {
|
||||
const maxRetries = ~~error.request.request.retries;
|
||||
const after = ~~error.request.request.retryAfter;
|
||||
options.request.retryCount = info.retryCount + 1;
|
||||
if (maxRetries > info.retryCount) {
|
||||
return after * state.retryAfterBaseValue;
|
||||
}
|
||||
});
|
||||
return limiter.schedule(
|
||||
requestWithGraphqlErrorHandling.bind(null, state, octokit, request),
|
||||
options
|
||||
);
|
||||
}
|
||||
async function requestWithGraphqlErrorHandling(state, octokit, request, options) {
|
||||
const response = await request(request, options);
|
||||
if (response.data && response.data.errors && response.data.errors.length > 0 && /Something went wrong while executing your query/.test(
|
||||
response.data.errors[0].message
|
||||
)) {
|
||||
const error = new RequestError(response.data.errors[0].message, 500, {
|
||||
request: options,
|
||||
response
|
||||
});
|
||||
return errorRequest(state, octokit, error, options);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
export {
|
||||
wrapRequest
|
||||
};
|
||||
Reference in New Issue
Block a user