From d6eb02bb281b1e32a65567397ac3c9568a4687fe Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 3 Apr 2026 14:44:06 +0300 Subject: [PATCH] feat: add FontFetchError and FontParseError typed errors --- .../model/store/appliedFontsStore/errors.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/entities/Font/model/store/appliedFontsStore/errors.ts diff --git a/src/entities/Font/model/store/appliedFontsStore/errors.ts b/src/entities/Font/model/store/appliedFontsStore/errors.ts new file mode 100644 index 0000000..f7201bb --- /dev/null +++ b/src/entities/Font/model/store/appliedFontsStore/errors.ts @@ -0,0 +1,35 @@ +/** + * Thrown when a font file cannot be retrieved from the network or cache. + * + * @property url - The URL that was requested. + * @property cause - The underlying error, if any. + * @property status - HTTP status code. Present on HTTP errors, absent on network failures. + */ +export class FontFetchError extends Error { + readonly name = 'FontFetchError'; + + constructor( + public readonly url: string, + public readonly cause?: unknown, + public readonly status?: number, + ) { + super(status ? `HTTP ${status} fetching font: ${url}` : `Network error fetching font: ${url}`); + } +} + +/** + * Thrown by {@link loadFont} when a font buffer cannot be parsed into a {@link FontFace}. + * + * @property fontName - The display name of the font that failed to parse. + * @property cause - The underlying error from the FontFace API. + */ +export class FontParseError extends Error { + readonly name = 'FontParseError'; + + constructor( + public readonly fontName: string, + public readonly cause?: unknown, + ) { + super(`Failed to parse font: ${fontName}`); + } +}