Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(response => {
url = response.url;
status = response.status;
for (const keyAndValue of response.headers) {
headers[keyAndValue[0]] = keyAndValue[1];
}
if (status === 204 || status === 205) {
return;
}
// GitHub API returns 200 for HEAD requsets
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new RequestError(response.statusText, status, {
headers,
request: requestOptions
});
}
if (status === 304) {
throw new RequestError("Not modified", status, {
headers,
request: requestOptions
});
}
if (status >= 400) {
return response
.text()
.then(message => {
const error = new RequestError(message, status, {
headers,
}
if (status === 204 || status === 205) {
return;
}
// GitHub API returns 200 for HEAD requsets
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new RequestError(response.statusText, status, {
headers,
request: requestOptions
});
}
if (status === 304) {
throw new RequestError("Not modified", status, {
headers,
request: requestOptions
});
}
if (status >= 400) {
return response
.text()
.then(message => {
const error = new RequestError(message, status, {
headers,
request: requestOptions
});
try {
let responseBody = JSON.parse(error.message);
Object.assign(error, responseBody);
let errors = responseBody.errors;
.then((response) => {
url = response.url;
status = response.status;
for (const keyAndValue of response.headers) {
headers[keyAndValue[0]] = keyAndValue[1];
}
if (status === 204 || status === 205) {
return;
}
// GitHub API returns 200 for HEAD requests
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new RequestError(response.statusText, status, {
headers,
request: requestOptions,
});
}
if (status === 304) {
throw new RequestError("Not modified", status, {
headers,
request: requestOptions,
});
}
if (status >= 400) {
return response
.text()
.then((message) => {
const error = new RequestError(message, status, {
headers,
.then(message => {
const error = new RequestError(message, status, {
headers,
request: requestOptions
});
try {
let responseBody = JSON.parse(error.message);
Object.assign(error, responseBody);
let errors = responseBody.errors;
// Assumption `errors` would always be in Array Fotmat
error.message =
error.message + ": " + errors.map(JSON.stringify).join(", ");
}
catch (e) {
// ignore, see octokit/rest.js#684
}
throw error;
});
} // GitHub API returns 200 for HEAD requsets
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new requestError.RequestError(response.statusText, status, {
headers,
request: requestOptions
});
}
if (status === 304) {
throw new requestError.RequestError("Not modified", status, {
headers,
request: requestOptions
});
}
if (status >= 400) {
return response.text().then(message => {
const error = new requestError.RequestError(message, status, {
headers,
request: requestOptions
});
try {
Object.assign(error, JSON.parse(error.message));
} catch (e) {// ignore, see octokit/rest.js#684
}
.then(response => {
url = response.url;
status = response.status;
for (const keyAndValue of response.headers) {
headers[keyAndValue[0]] = keyAndValue[1];
}
if (status === 204 || status === 205) {
return;
}
// GitHub API returns 200 for HEAD requsets
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new RequestError(response.statusText, status, {
headers,
request: requestOptions
});
}
if (status === 304) {
throw new RequestError("Not modified", status, {
headers,
request: requestOptions
});
}
if (status >= 400) {
return response
.text()
.then(message => {
const error = new RequestError(message, status, {
headers,
.then(message => {
const error = new RequestError(message, status, {
headers,
request: requestOptions
});
try {
let responseBody = JSON.parse(error.message);
Object.assign(error, responseBody);
let errors = responseBody.errors;
// Assumption `errors` would always be in Array Fotmat
error.message =
error.message + ": " + errors.map(JSON.stringify).join(", ");
}
catch (e) {
// ignore, see octokit/rest.js#684
}
throw error;
});
test('should handle octokit client error (without retries)', async t => {
const github = factory(GitHub, { options: { github: { tokenRef, remoteUrl, host } } });
const stub = sinon.stub(github.client.repos, 'createRelease');
stub.throws(new RequestError('Not found', 404, { request: { url: '', headers: {} } }));
interceptAuthentication();
interceptCollaborator();
await t.throwsAsync(runTasks(github), { instanceOf: GitHubClientError, message: '404 (Not found)' });
t.is(stub.callCount, 1);
stub.restore();
});
}).catch(error => {
if (error instanceof requestError.RequestError) {
throw error;
}
throw new requestError.RequestError(error.message, 500, {
headers,
request: requestOptions
});
});
}
.catch(error => {
if (error instanceof RequestError) {
throw error;
}
throw new RequestError(error.message, 500, {
headers,
request: requestOptions
});
});
}