Skip to content

Commit

Permalink
fix: Unify error objects with GitHub errors. (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichi10 authored Mar 8, 2021
1 parent e233066 commit e8a4caf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function checkResponseError(response, caller) {

const error = new Error(`${errorCode} Reason "${errorReason}" Caller "${caller}"`);

error.code = errorCode;
error.status = errorCode;
throw error;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"mocha": "^8.2.1",
"mocha-multi-reporters": "^1.5.1",
"mocha-sonarqube-reporter": "^1.0.2",
"nyc": "^15.0.0",
"mockery": "^2.0.0",
"nyc": "^15.0.0",
"sinon": "^1.17.7",
"sinon-as-promised": "^4.0.2"
},
Expand Down
18 changes: 16 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '404 Reason "404 Project Not Found" ' +
'Caller "_parseUrl"');
assert.match(error.status, 404);
});
});

Expand All @@ -235,6 +236,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '500 Reason "Internal Server Error" ' +
'Caller "_parseUrl"');
assert.match(error.status, 500);
});
});

Expand Down Expand Up @@ -437,6 +439,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "_decorateAuthor"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -527,6 +530,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "lookupScmUri"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -667,6 +671,7 @@ describe('index', function () {
assert.calledTwice(requestMock);
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "_decorateCommit: commitLookup"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -745,6 +750,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "_getCommitSha"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -831,6 +837,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "_addPrComment"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -910,6 +917,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "_getFile"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -1177,6 +1185,7 @@ describe('index', function () {
}).catch((error) => {
assert.match(error.message, '404 Reason "Resource not found" ' +
'Caller "_getPermissions"');
assert.match(error.status, 404);
});
});

Expand Down Expand Up @@ -1271,6 +1280,7 @@ describe('index', function () {
assert.calledWith(requestMock, expectedOptions);
assert.match(error.message, '401 Reason "Access token expired" ' +
'Caller "_updateCommitStatus"');
assert.match(error.status, 401);
});
});

Expand Down Expand Up @@ -1531,6 +1541,7 @@ describe('index', function () {
assert.match(error.message, '403 Reason "Your credentials lack one or more ' +
'required privilege scopes." ' +
'Caller "_findWebhook"');
assert.match(error.status, 403);
});
});

Expand All @@ -1557,6 +1568,7 @@ describe('index', function () {
}).then(assert.fail, (error) => {
assert.match(error.message, '500 Reason "{"blah":"undefined"}" ' +
'Caller "_findWebhook"');
assert.match(error.status, 500);
});
});

Expand Down Expand Up @@ -1589,6 +1601,7 @@ describe('index', function () {
assert.match(error.message, '403 Reason "Your credentials lack one or more ' +
'required privilege scopes." ' +
'Caller "_createWebhook"');
assert.match(error.status, 403);
});
});

Expand Down Expand Up @@ -1633,10 +1646,11 @@ describe('index', function () {
'merge_requests_events',
'push_events'
]
}).then(assert.fail, (err) => {
assert.strictEqual(err.message, '403 Reason "Your credentials lack one or more ' +
}).then(assert.fail, (error) => {
assert.strictEqual(error.message, '403 Reason "Your credentials lack one or more ' +
'required privilege scopes." ' +
'Caller "_createWebhook"');
assert.match(error.status, 403);
});
});
});
Expand Down

0 comments on commit e8a4caf

Please sign in to comment.