chore: rename FetchFonts to GetFonts
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
type FontshareParams,
|
||||
fetchFontshareFonts,
|
||||
} from '../../api';
|
||||
import { normalizeFontshareFonts } from '../../lib';
|
||||
import type { UnifiedFont } from '../types';
|
||||
|
||||
/**
|
||||
* Query function for fetching fonts from Fontshare.
|
||||
*
|
||||
* @param params - The parameters for fetching fonts from Fontshare (E.g. search query, page number, etc.).
|
||||
* @returns A promise that resolves with an array of UnifiedFont objects representing the fonts found in Fontshare.
|
||||
*/
|
||||
export async function fetchFontshareFontsQuery(params: FontshareParams): Promise<UnifiedFont[]> {
|
||||
try {
|
||||
const response = await fetchFontshareFonts(params);
|
||||
return normalizeFontshareFonts(response.fonts);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('Failed to fetch')) {
|
||||
throw new Error(
|
||||
'Unable to connect to Fontshare. Please check your internet connection.',
|
||||
);
|
||||
}
|
||||
if (error.message.includes('404')) {
|
||||
throw new Error('Font not found in Fontshare catalog.');
|
||||
}
|
||||
}
|
||||
throw new Error('Failed to load fonts from Fontshare.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user