Skip to content

Commit

Permalink
Add custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thejollyrogers committed May 14, 2015
1 parent 4ff0b3d commit a66eccc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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");

/**
* 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.
*/
function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export {Server} from "./server";
export {Operation} from "./operation";
export {Keypair} from "stellar-base";
export {Memo} from "./memo";
export {xdr} from "stellar-base";
export {xdr} from "stellar-base";
export * from "./errors";

0 comments on commit a66eccc

Please sign in to comment.