Skip to content

Commit

Permalink
fix: use status rather than code in @octokit/rest.js HttpError
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 22, 2018
1 parent f004904 commit 5a3e287
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/get-client.js
Expand Up @@ -11,7 +11,7 @@ const GH_ROUTES = require('@octokit/rest/plugins/rest-api-endpoints/routes');
const {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT} = require('./definitions/rate-limit');

/**
* Http error codes for which to not retry.
* Http error status for which to not retry.
*/
const SKIP_RETRY_CODES = [400, 401, 403];

Expand Down Expand Up @@ -98,7 +98,7 @@ const handler = (globalThrottler, limitKey) => ({
try {
return await throttler.wrap(func)(...args);
} catch (error) {
if (SKIP_RETRY_CODES.includes(error.code)) {
if (SKIP_RETRY_CODES.includes(error.status)) {
throw new pRetry.AbortError(error);
}
throw error;
Expand Down
2 changes: 1 addition & 1 deletion lib/success.js
Expand Up @@ -94,7 +94,7 @@ module.exports = async (pluginConfig, context) => {
logger.log("Skip comment and labels on issue #%d as it's open: %s", issue.number);
}
} catch (error) {
if (error.code === 404) {
if (error.status === 404) {
logger.error("Failed to add a comment to the issue #%d as it doesn't exists.", issue.number);
} else {
errors.push(error);
Expand Down
4 changes: 2 additions & 2 deletions lib/verify.js
Expand Up @@ -62,9 +62,9 @@ module.exports = async (pluginConfig, context) => {
errors.push(getError('EGHNOPERMISSION', {owner, repo}));
}
} catch (error) {
if (error.code === 401) {
if (error.status === 401) {
errors.push(getError('EINVALIDGHTOKEN', {owner, repo}));
} else if (error.code === 404) {
} else if (error.status === 404) {
errors.push(getError('EMISSINGREPO', {owner, repo}));
} else {
throw error;
Expand Down
4 changes: 2 additions & 2 deletions test/find-sr-issue.test.js
Expand Up @@ -107,7 +107,7 @@ test.serial('Retries 4 times', async t => {

const error = await t.throws(findSRIssues(client, title, owner, repo));

t.is(error.code, 422);
t.is(error.status, 422);
t.true(github.isDone());
});

Expand All @@ -125,6 +125,6 @@ test.serial('Do not retry on 401 error', async t => {

const error = await t.throws(findSRIssues(client, title, owner, repo));

t.is(error.code, 401);
t.is(error.status, 401);
t.true(github.isDone());
});
2 changes: 1 addition & 1 deletion test/publish.test.js
Expand Up @@ -229,6 +229,6 @@ test.serial('Throw error without retries for 400 error', async t => {

const error = await t.throws(publish(pluginConfig, {cwd, env, options, nextRelease, logger: t.context.logger}));

t.is(error.code, 400);
t.is(error.status, 400);
t.true(github.isDone());
});
4 changes: 2 additions & 2 deletions test/success.test.js
Expand Up @@ -678,8 +678,8 @@ test.serial('Ignore errors when adding comments and closing issues', async t =>
success(pluginConfig, {env, options, commits, nextRelease, releases, logger: t.context.logger})
);

t.is(error1.code, 400);
t.is(error2.code, 500);
t.is(error1.status, 400);
t.is(error2.status, 500);
t.true(t.context.error.calledWith('Failed to add a comment to the issue #%d.', 1));
t.true(t.context.error.calledWith('Failed to close the issue #%d.', 2));
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 2, 'https://github.com/successcomment-2'));
Expand Down
2 changes: 1 addition & 1 deletion test/verify.test.js
Expand Up @@ -408,7 +408,7 @@ test.serial('Throw error if github return any other errors', async t => {
verify({}, {env, options: {repositoryUrl: `https://github.com/${owner}/${repo}.git`}, logger: t.context.logger})
);

t.is(error.code, 500);
t.is(error.status, 500);
t.true(github.isDone());
});

Expand Down

0 comments on commit 5a3e287

Please sign in to comment.