UNPKG

747 BJavaScriptView Raw
1var ExtendableBuiltin = require("./extendablebuiltin");
2var inherits = require("util").inherits;
3
4inherits(ExtendableError, ExtendableBuiltin(Error));
5
6// From: http://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax
7function ExtendableError(message) {
8 ExtendableError.super_.call(this);
9 this.message = message;
10 this.stack = new Error(message).stack;
11 this.name = this.constructor.name;
12}
13
14// Hack. Likely won't be formatted correctly when there are
15// 10 or more errors. But if there's 10 or more errors, I'm guessing
16// formatting won't matter so much.
17ExtendableError.prototype.formatForMocha = function() {
18 this.message = this.message.replace(/\n/g, "\n ");
19};
20
21module.exports = ExtendableError;