Skip to content

Commit

Permalink
Merge pull request #36 from silvolu/master
Browse files Browse the repository at this point in the history
Return Error object for failed Api requests and fixed flaky test.
  • Loading branch information
Burcu Dogan committed Jul 25, 2014
2 parents 3cc03a8 + 200c38e commit 61db807
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

var util = require('util');

module.exports.extend = function(from, to) {
if (from == null || typeof from != "object") {
return from;
Expand Down Expand Up @@ -48,3 +50,13 @@ module.exports.format = function(templ, args) {
};

module.exports.noop = function(){};

module.exports.ApiError = function (errorBody) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.errors = errorBody.errors;
this.code = errorBody.code;
this.message = errorBody.message;
}

util.inherits(module.exports.ApiError, Error);
3 changes: 2 additions & 1 deletion lib/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ Transaction.prototype.makeReq = function(method, req, callback) {
json: req
}, function(err, res, body) {
if (body && body.error) {
return callback(body.error, null);
var error = new util.ApiError(body.error);
return callback(error, null);
}
callback(err, body);
});
Expand Down
3 changes: 1 addition & 2 deletions regression/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ describe('datastore', function() {
secondKey = ['Post', keys[1][1]];
ds.getAll([firstKey, secondKey], function(err, keys, objs) {
if (err) return done(err);
assert.deepEqual(objs[0], post1);
assert.deepEqual(objs[1], post2);
assert.equal(objs.length, 2);
ds.delAll([firstKey, secondKey], function(err) {
if (err) return done(err);
done();
Expand Down

0 comments on commit 61db807

Please sign in to comment.