2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-08 14:20:57 +00:00

chore: add try catch to custom loader in utils

This commit is contained in:
Vjacheslav Trushkin 2023-08-12 18:54:27 +03:00
parent 22d7d8b889
commit 8b2af7135a

View File

@ -1,6 +1,7 @@
import { getCustomIcon } from './custom'; import { getCustomIcon } from './custom';
import type { UniversalIconLoader } from './types'; import type { UniversalIconLoader } from './types';
import { searchForIcon } from './modern'; import { searchForIcon } from './modern';
import { IconifyJSON } from '@iconify/types';
export const loadIcon: UniversalIconLoader = async ( export const loadIcon: UniversalIconLoader = async (
collection, collection,
@ -11,11 +12,17 @@ export const loadIcon: UniversalIconLoader = async (
if (custom) { if (custom) {
if (typeof custom === 'function') { if (typeof custom === 'function') {
const result = await custom(icon); let result: string | IconifyJSON | undefined;
try {
result = await custom(icon);
} catch {
return;
}
if (result) { if (result) {
if (typeof result === 'string') { if (typeof result === 'string') {
return await getCustomIcon( return await getCustomIcon(
() => result, () => result as string,
collection, collection,
icon, icon,
options options
@ -42,6 +49,4 @@ export const loadIcon: UniversalIconLoader = async (
return await getCustomIcon(custom, collection, icon, options); return await getCustomIcon(custom, collection, icon, options);
} }
} }
return undefined;
}; };