UNPKG

@pallad/common-errors

Version:
29 lines (28 loc) 998 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotFoundError = void 0; const BaseError_1 = require("./BaseError"); /** * Indicates that an entity does not exist. */ class NotFoundError extends BaseError_1.BaseError { constructor(message, references) { super(message, 'NotFoundError'); this.references = references; } /** * Helper that creates new error with formatted message that use entity name and stringified references */ static entity(name, references) { const referenceString = references ? getReferencesString(references) : ''; return new NotFoundError(`${name} not found${referenceString ? ` - ${referenceString}` : ''}`, references); } } exports.NotFoundError = NotFoundError; function getReferencesString(references) { return Object.keys(references) .reduce((result, key) => { return result.concat([`${key}: ${references[key]}`]); }, []) .join(', '); }