UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

65 lines 1.95 kB
/** * @module Codec */ import {} from "../../utilities/_module.js"; /** * The error occurs when a value is unable to be encoded. * * IMPORT_PATH: `"@daiso-tech/core/codec/contracts"` * @group Errors */ export class EncodingError extends Error { static create(error) { return new EncodingError(`Encoding error "${String(error)}" occurred`, error); } /** * Note: Do not instantiate `EncodingError` directly via the constructor. Use the static `create()` factory method instead. * The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors. * @internal */ constructor(message, cause) { super(message, { cause }); this.name = EncodingError.name; } } /** * The error occurs when a value is unable to be decoded. * * IMPORT_PATH: `"@daiso-tech/core/codec/contracts"` * @group Errors */ export class DecodingError extends Error { static create(error) { return new DecodingError(`Decoding error "${String(error)}" occurred`, error); } /** * Note: Do not instantiate `DecodingError` directly via the constructor. Use the static `create()` factory method instead. * The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors. * @internal */ constructor(message, cause) { super(message, { cause }); this.name = DecodingError.name; } } /** * IMPORT_PATH: `"@daiso-tech/core/codec/contracts"` * @group Errors */ export const CODEC_ERRORS = { Encoding: EncodingError, Decoding: DecodingError, }; /** * IMPORT_PATH: `"@daiso-tech/core/codec/contracts"` * @group Errors */ export function isCodecError(value) { for (const errorClass of Object.values(CODEC_ERRORS)) { if (value instanceof errorClass) { return true; } } return false; } //# sourceMappingURL=codec.errors.js.map