Skip to content

Commit 275cf42

Browse files
committed
Fixed missing error checks
We were not checking for errors and passing them to callbacks in api.js in three places: In get() removeDeployKey() deleteHooks() This was causing 8 of the unit tests to fail. Fixed.
1 parent be83aa8 commit 275cf42

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/api.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var _ = require('lodash');
22
var async = require('async');
33
var superagent = require('superagent');
44
var debug = require('debug')('strider-gitlab:api');
5+
var util = require('util');
56

67
module.exports = {
78
get: get,
@@ -39,8 +40,13 @@ function get(config, uri, done) {
3940
.set('User-Agent', 'StriderCD (http://stridercd.com)')
4041
.end(function (error, res) {
4142
res = res || {};
43+
44+
if (error) {
45+
return done(error, null, null);
46+
}
47+
4248
debug('Response body type: ' + typeof res.body);
43-
debug('Response body received: ' + JSON.stringify(res.body));
49+
debug('Response body received: ' + util.inspect(res.body, false, 10, true));
4450
if (res.error) {
4551
return done(res.error, null, res);
4652
}
@@ -103,6 +109,10 @@ function deleteHooks(config, repo_id, url, callback) {
103109
.end(function (err, res) {
104110
var deleted = false;
105111

112+
if (err) {
113+
return callback(err);
114+
}
115+
106116
if (!res) {
107117
return callback(new Error("Empty response."));
108118
}
@@ -156,6 +166,11 @@ function removeDeployKey(config, repo_id, title, callback) {
156166
.query(qpm)
157167
.set('User-Agent', 'StriderCD (http://stridercd.com)')
158168
.end(function (err, res) {
169+
170+
if (err) {
171+
return callback(err);
172+
}
173+
159174
var deleted = false;
160175

161176
if (!res) {

lib/webapp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ module.exports = {
3030
api.get(config, 'projects', function (err, repos) {
3131
if (err) return done(err);
3232

33-
if(!repos) {
34-
return done(new Error("Could not get a list of projects from the GitLab repository. Please check the configuration in Account->GitLab."));
33+
if (!repos) {
34+
return done(new Error("Could not get a list of projects from the GitLab repository. Please check the configuration in Account->GitLab."));
3535
}
3636

3737
// Parse and filter only git repos
@@ -59,7 +59,7 @@ module.exports = {
5959

6060
debug("Getting URI " + uri);
6161
api.get(account, uri, function (err, branches) {
62-
debug("We get the following as branches: " + JSON.stringify(branches));
62+
debug("We get the following as branches: " + util.inspect(branches, false, 10, true));
6363

6464
done(err, _.map(branches || [], function (branch) {
6565
return branch.name;

0 commit comments

Comments
 (0)