UNPKG

ts-stream

Version:

Type-safe object streams with seamless support for backpressure, ending, and error handling

59 lines 2.13 kB
"use strict"; /** * Base class for custom errors. * * Copyright (C) 2015 Martin Poelstra * License: MIT */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var BaseError = /** @class */ (function (_super) { __extends(BaseError, _super); function BaseError(name, message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; var fixStack = false; // This fixes the prototype chain if it's broken (when emitting for ES 5 or lower) if (_this.constructor !== _newTarget) { Object.setPrototypeOf(_this, _newTarget.prototype); fixStack = true; } // This occurs when the error is not thrown but only created in IE if (!("stack" in _this)) { fixStack = true; } _this.name = name; if (fixStack) { // This.name and this.message must be set correctly in order to fix the stack correctly if (Error.captureStackTrace) { Error.captureStackTrace(_this, _newTarget); } else { var error = new Error(_this.message); error.name = _this.name; try { throw error; } catch (error) { _this.stack = error.stack || String(error); } } } return _this; } return BaseError; }(Error)); exports.default = BaseError; //# sourceMappingURL=BaseError.js.map