react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / har-validator / node_modules / bluebird / js / main / errors.js
81160 views"use strict";1var es5 = require("./es5.js");2var Objectfreeze = es5.freeze;3var util = require("./util.js");4var inherits = util.inherits;5var notEnumerableProp = util.notEnumerableProp;67function subError(nameProperty, defaultMessage) {8function SubError(message) {9if (!(this instanceof SubError)) return new SubError(message);10notEnumerableProp(this, "message",11typeof message === "string" ? message : defaultMessage);12notEnumerableProp(this, "name", nameProperty);13if (Error.captureStackTrace) {14Error.captureStackTrace(this, this.constructor);15} else {16Error.call(this);17}18}19inherits(SubError, Error);20return SubError;21}2223var _TypeError, _RangeError;24var Warning = subError("Warning", "warning");25var CancellationError = subError("CancellationError", "cancellation error");26var TimeoutError = subError("TimeoutError", "timeout error");27var AggregateError = subError("AggregateError", "aggregate error");28try {29_TypeError = TypeError;30_RangeError = RangeError;31} catch(e) {32_TypeError = subError("TypeError", "type error");33_RangeError = subError("RangeError", "range error");34}3536var methods = ("join pop push shift unshift slice filter forEach some " +37"every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");3839for (var i = 0; i < methods.length; ++i) {40if (typeof Array.prototype[methods[i]] === "function") {41AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];42}43}4445es5.defineProperty(AggregateError.prototype, "length", {46value: 0,47configurable: false,48writable: true,49enumerable: true50});51AggregateError.prototype["isOperational"] = true;52var level = 0;53AggregateError.prototype.toString = function() {54var indent = Array(level * 4 + 1).join(" ");55var ret = "\n" + indent + "AggregateError of:" + "\n";56level++;57indent = Array(level * 4 + 1).join(" ");58for (var i = 0; i < this.length; ++i) {59var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";60var lines = str.split("\n");61for (var j = 0; j < lines.length; ++j) {62lines[j] = indent + lines[j];63}64str = lines.join("\n");65ret += str + "\n";66}67level--;68return ret;69};7071function OperationalError(message) {72if (!(this instanceof OperationalError))73return new OperationalError(message);74notEnumerableProp(this, "name", "OperationalError");75notEnumerableProp(this, "message", message);76this.cause = message;77this["isOperational"] = true;7879if (message instanceof Error) {80notEnumerableProp(this, "message", message.message);81notEnumerableProp(this, "stack", message.stack);82} else if (Error.captureStackTrace) {83Error.captureStackTrace(this, this.constructor);84}8586}87inherits(OperationalError, Error);8889var errorTypes = Error["__BluebirdErrorTypes__"];90if (!errorTypes) {91errorTypes = Objectfreeze({92CancellationError: CancellationError,93TimeoutError: TimeoutError,94OperationalError: OperationalError,95RejectionError: OperationalError,96AggregateError: AggregateError97});98notEnumerableProp(Error, "__BluebirdErrorTypes__", errorTypes);99}100101module.exports = {102Error: Error,103TypeError: _TypeError,104RangeError: _RangeError,105CancellationError: errorTypes.CancellationError,106OperationalError: errorTypes.OperationalError,107TimeoutError: errorTypes.TimeoutError,108AggregateError: errorTypes.AggregateError,109Warning: Warning110};111112113