feat(FontStore): implement fetchPage with error wrapping
This commit is contained in:
@@ -5,7 +5,15 @@ import {
|
|||||||
type InfiniteQueryObserverResult,
|
type InfiniteQueryObserverResult,
|
||||||
type QueryFunctionContext,
|
type QueryFunctionContext,
|
||||||
} from '@tanstack/query-core';
|
} 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';
|
import type { UnifiedFont } from '../../types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,8 +183,24 @@ export class FontStore {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchPage(_params: ProxyFontsParams): Promise<FontPage> {
|
private async fetchPage(params: ProxyFontsParams): Promise<FontPage> {
|
||||||
return { fonts: [], total: 0, limit: 0, offset: 0 };
|
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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user