all files / src/ errors.js

100% Statements 20/20
50% Branches 1/2
100% Functions 3/3
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                            
Error.subclass = function(errorName) {
  var newError = function(message, data) {
    this.name    = errorName;
    this.message = (message || "");
    this.data = data;
  };
 
  newError.subclass = this.subclass;
  inherits(newError, this);
 
  return newError;
};
 
export var NetworkError = Error.subclass("NetworkError");
export var NotFoundError = NetworkError.subclass("NotFoundError");
export var BadRequestError = Error.subclass("BadRequestError");
export var BadResponseError = Error.subclass("BadResponseError");
 
/**
 * From: https://github.com/joyent/node/blob/master/lib/util.js
 * Inherit the prototype methods from one constructor into another.
 *
 * The Function.prototype.inherits from lang.js rewritten as a standalone
 * function (not on Function.prototype). NOTE: If this file is to be loaded
 * during bootstrapping this function needs to be rewritten using some native
 * functions as prototype setup using normal JavaScript does not work as
 * expected during bootstrapping (see mirror.js in r114903).
 *
 * @param {function} ctor Constructor function which needs to inherit the
 *     prototype.
 * @param {function} superCtor Constructor function to inherit prototype from.
 * @private
 */
function inherits(ctor, superCtor) {
  ctor.super_ = superCtor;
  ctor.prototype = Object.create(superCtor.prototype, {
    constructor: {
      value: ctor,
      enumerable: false,
      writable: true,
      configurable: true
    }
  });
}