Skip to content

Commit d539bf0

Browse files
author
Burcu Dogan
committed
Merge pull request #153 from proppy/add-error-handling
datastore/request: add API error handling
2 parents bac5d90 + f06a4b1 commit d539bf0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/common/util.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ function handleResp(err, resp, body, callback) {
149149
return;
150150
}
151151
if (resp && (resp.statusCode < 200 || resp.statusCode > 299)) {
152-
callback(new Error('error during request, statusCode: ' + resp.statusCode));
152+
var error = 'error during request, statusCode: ' + resp.statusCode;
153+
if (body) {
154+
error += ', body: ' + body;
155+
}
156+
callback(new Error(error));
153157
return;
154158
}
155159
callback(null, body, resp);

lib/datastore/transaction.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,13 @@ Transaction.prototype.makeReq = function(method, req, respType, callback) {
446446
buffer = Buffer.concat([buffer, chunk]);
447447
});
448448
resp.on('end', function() {
449-
callback(null, respType.decode(buffer));
449+
util.handleResp(null, resp, buffer.toString(), function(err) {
450+
if (err) {
451+
callback(err);
452+
return;
453+
}
454+
callback(null, respType.decode(buffer));
455+
});
450456
});
451457
});
452458
remoteStream.on('error', callback);

0 commit comments

Comments
 (0)