From a9e4633b64a7870793763a3c4621851837b694bf Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Wed, 8 Apr 2026 09:50:16 +0300 Subject: [PATCH] feat(FontStore): implement fetchPage with error wrapping --- .../model/store/fontStore/fontStore.svelte.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/entities/Font/model/store/fontStore/fontStore.svelte.ts b/src/entities/Font/model/store/fontStore/fontStore.svelte.ts index 78ff5f3..9b10bf7 100644 --- a/src/entities/Font/model/store/fontStore/fontStore.svelte.ts +++ b/src/entities/Font/model/store/fontStore/fontStore.svelte.ts @@ -5,7 +5,15 @@ import { type InfiniteQueryObserverResult, type QueryFunctionContext, } from '@tanstack/query-core'; -import type { ProxyFontsParams } from '../../../api'; +import { + type ProxyFontsParams, + type ProxyFontsResponse, + fetchProxyFonts, +} from '../../../api'; +import { + FontNetworkError, + FontResponseError, +} from '../../../lib/errors/errors'; import type { UnifiedFont } from '../../types'; /** @@ -175,8 +183,24 @@ export class FontStore { }; } - private async fetchPage(_params: ProxyFontsParams): Promise { - return { fonts: [], total: 0, limit: 0, offset: 0 }; + private async fetchPage(params: ProxyFontsParams): Promise { + let response: ProxyFontsResponse; + try { + response = await fetchProxyFonts(params); + } catch (cause) { + throw new FontNetworkError(cause); + } + + if (!response) throw new FontResponseError('response', response); + if (!response.fonts) throw new FontResponseError('response.fonts', response.fonts); + if (!Array.isArray(response.fonts)) throw new FontResponseError('response.fonts', response.fonts); + + return { + fonts: response.fonts, + total: response.total ?? 0, + limit: response.limit ?? params.limit ?? 50, + offset: response.offset ?? params.offset ?? 0, + }; } }