UNPKG

stellar-plus

Version:

beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain

38 lines (37 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StellarPlusError = void 0; const types_1 = require("./types"); class StellarPlusError extends Error { constructor(e) { super(e.message); this.code = e.code; this.source = e.source; this.details = e.details; this.diagnostic = e.diagnostic; this.meta = e.meta; this.name = this.constructor.name; } static unexpectedError(args) { var _a, _b, _c, _d; const code = (_a = args === null || args === void 0 ? void 0 : args.code) !== null && _a !== void 0 ? _a : types_1.GeneralErrorCodes.ER000; const source = (_b = args === null || args === void 0 ? void 0 : args.source) !== null && _b !== void 0 ? _b : 'StellarPlus'; const message = (_c = args === null || args === void 0 ? void 0 : args.message) !== null && _c !== void 0 ? _c : 'Unexpected error!'; const details = (_d = args === null || args === void 0 ? void 0 : args.details) !== null && _d !== void 0 ? _d : 'An unexpected error occurred.'; const meta = args === null || args === void 0 ? void 0 : args.meta; return new StellarPlusError({ code, source, message, details, meta: Object.assign(Object.assign({}, meta), { error: args === null || args === void 0 ? void 0 : args.error }), }); } static fromUnkownError(error) { if (error instanceof StellarPlusError) { return error; } return StellarPlusError.unexpectedError({ error: error }); } } exports.StellarPlusError = StellarPlusError;