diff --git a/lib/common/util.js b/lib/common/util.js index 64a1fbc2cba..438ebfbdfb5 100644 --- a/lib/common/util.js +++ b/lib/common/util.js @@ -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; @@ -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); diff --git a/lib/datastore/index.js b/lib/datastore/index.js index 94a3f01b1aa..74a434636b2 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -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); }); diff --git a/regression/datastore.js b/regression/datastore.js index 6ec90b84dd5..71add1494be 100644 --- a/regression/datastore.js +++ b/regression/datastore.js @@ -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();