UNPKG

@zcatalyst/utils

Version:

46 lines (45 loc) 1.1 kB
'use strict'; export 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()); } } export class PrefixedCatalystError extends CatalystError { constructor(codePrefix, code, message, value, statusCode) { super({ code: `${codePrefix}/${code}`, message, value, statusCode }); this.codePrefix = codePrefix; } } export class CatalystAppError extends PrefixedCatalystError { constructor(code, message, value) { super('app', code, message, value); } }