Skip to content

Commit

Permalink
Added custom error class for api errors
Browse files Browse the repository at this point in the history
  • Loading branch information
silvolu committed Jul 25, 2014
1 parent da5ddcc commit 200c38e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 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: 1 addition & 2 deletions lib/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ Transaction.prototype.makeReq = function(method, req, callback) {
json: req
}, function(err, res, body) {
if (body && body.error) {
var error = new Error(body.error.errors[0].reason + ': ' +
body.error.errors[0].message);
var error = new util.ApiError(body.error);
return callback(error, null);
}
callback(err, body);
Expand Down

0 comments on commit 200c38e

Please sign in to comment.