2 var es5 = require("./es5");
3 var Objectfreeze = es5.freeze;
4 var util = require("./util");
5 var inherits = util.inherits;
6 var notEnumerableProp = util.notEnumerableProp;
8 function subError(nameProperty, defaultMessage) {
9 function SubError(message) {
10 if (!(this instanceof SubError)) return new SubError(message);
11 notEnumerableProp(this, "message",
12 typeof message === "string" ? message : defaultMessage);
13 notEnumerableProp(this, "name", nameProperty);
14 if (Error.captureStackTrace) {
15 Error.captureStackTrace(this, this.constructor);
20 inherits(SubError, Error);
24 var _TypeError, _RangeError;
25 var Warning = subError("Warning", "warning");
26 var CancellationError = subError("CancellationError", "cancellation error");
27 var TimeoutError = subError("TimeoutError", "timeout error");
28 var AggregateError = subError("AggregateError", "aggregate error");
30 _TypeError = TypeError;
31 _RangeError = RangeError;
33 _TypeError = subError("TypeError", "type error");
34 _RangeError = subError("RangeError", "range error");
37 var methods = ("join pop push shift unshift slice filter forEach some " +
38 "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
40 for (var i = 0; i < methods.length; ++i) {
41 if (typeof Array.prototype[methods[i]] === "function") {
42 AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
46 es5.defineProperty(AggregateError.prototype, "length", {
52 AggregateError.prototype["isOperational"] = true;
54 AggregateError.prototype.toString = function() {
55 var indent = Array(level * 4 + 1).join(" ");
56 var ret = "\n" + indent + "AggregateError of:" + "\n";
58 indent = Array(level * 4 + 1).join(" ");
59 for (var i = 0; i < this.length; ++i) {
60 var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
61 var lines = str.split("\n");
62 for (var j = 0; j < lines.length; ++j) {
63 lines[j] = indent + lines[j];
65 str = lines.join("\n");
72 function OperationalError(message) {
73 if (!(this instanceof OperationalError))
74 return new OperationalError(message);
75 notEnumerableProp(this, "name", "OperationalError");
76 notEnumerableProp(this, "message", message);
78 this["isOperational"] = true;
80 if (message instanceof Error) {
81 notEnumerableProp(this, "message", message.message);
82 notEnumerableProp(this, "stack", message.stack);
83 } else if (Error.captureStackTrace) {
84 Error.captureStackTrace(this, this.constructor);
88 inherits(OperationalError, Error);
90 var errorTypes = Error["__BluebirdErrorTypes__"];
92 errorTypes = Objectfreeze({
93 CancellationError: CancellationError,
94 TimeoutError: TimeoutError,
95 OperationalError: OperationalError,
96 RejectionError: OperationalError,
97 AggregateError: AggregateError
99 notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);
104 TypeError: _TypeError,
105 RangeError: _RangeError,
106 CancellationError: errorTypes.CancellationError,
107 OperationalError: errorTypes.OperationalError,
108 TimeoutError: errorTypes.TimeoutError,
109 AggregateError: errorTypes.AggregateError,