Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CircleCI] Extended existing try-catch block #1614

Merged
merged 3 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5921,17 +5921,16 @@ cache(function(data, match, sendBadge, request) {

var badgeData = getBadgeData('build', data);
request(apiUrl, {json:true}, function(err, res, data) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
if (data.message !== undefined){
badgeData.text[1] = data.message;
if (checkErrorResponse(badgeData, err, res)) {
sendBadge(format, badgeData);
return;
}
try {
if (data.message !== undefined){
badgeData.text[1] = data.message;
sendBadge(format, badgeData);
return;
}
var status = data[0].status;
switch(status) {
case 'success':
Expand Down
10 changes: 9 additions & 1 deletion services/circleci/circleci.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ t.create('circle ci (valid, with branch)')

t.create('circle ci (not found)')
.get('/project/github/PyvesB/EmptyRepo.json')
.expectJSON({name: 'build', value: 'Project not found'});
.expectJSON({name: 'build', value: 'not found'});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the explicit message. You can pass a custom "not found" message to checkErrorResponse to preserve the old behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted. I've nevertheless switched to a lower case P to be more consistent with what we use elsewhere.


t.create('circle ci (connection error)')
.get('/project/github/RedSparr0w/node-csgo-parser.json')
Expand All @@ -39,3 +39,11 @@ t.create('circle ci (unexpected response)')
.reply(invalidJSON)
)
.expectJSON({name: 'build', value: 'invalid'});

t.create('circle ci (no response data)')
.get('/project/github/RedSparr0w/node-csgo-parser.json')
.intercept(nock => nock('https://circleci.com')
.get('/api/v1.1/project/github/RedSparr0w/node-csgo-parser?filter=completed&limit=1')
.reply(200)
)
.expectJSON({ name: 'build', value: 'invalid' });