feat: add FontFetchError and FontParseError typed errors
This commit is contained in:
35
src/entities/Font/model/store/appliedFontsStore/errors.ts
Normal file
35
src/entities/Font/model/store/appliedFontsStore/errors.ts
Normal file
@@ -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}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user