UNPKG

@zcatalyst/utils

Version:

51 lines (50 loc) 1.37 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.CatalystAppError = exports.PrefixedCatalystError = exports.CatalystError = void 0; class CatalystError extends Error { constructor(errorInfo) { super(errorInfo.message); this.errorInfo = errorInfo; } get code() { return this.errorInfo?.code; } get message() { return this.errorInfo?.message; } get value() { return this.errorInfo?.value; } get statusCode() { return this.errorInfo.statusCode || 400; } toJSON() { return { code: this.code, message: this.message, value: this.value }; } toString() { return JSON.stringify(this.toJSON()); } } exports.CatalystError = CatalystError; class PrefixedCatalystError extends CatalystError { constructor(codePrefix, code, message, value, statusCode) { super({ code: `${codePrefix}/${code}`, message, value, statusCode }); this.codePrefix = codePrefix; } } exports.PrefixedCatalystError = PrefixedCatalystError; class CatalystAppError extends PrefixedCatalystError { constructor(code, message, value) { super('app', code, message, value); } } exports.CatalystAppError = CatalystAppError;