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:
parent
22d7d8b889
commit
8b2af7135a
@ -1,6 +1,7 @@
|
||||
import { getCustomIcon } from './custom';
|
||||
import type { UniversalIconLoader } from './types';
|
||||
import { searchForIcon } from './modern';
|
||||
import { IconifyJSON } from '@iconify/types';
|
||||
|
||||
export const loadIcon: UniversalIconLoader = async (
|
||||
collection,
|
||||
@ -11,11 +12,17 @@ export const loadIcon: UniversalIconLoader = async (
|
||||
|
||||
if (custom) {
|
||||
if (typeof custom === 'function') {
|
||||
const result = await custom(icon);
|
||||
let result: string | IconifyJSON | undefined;
|
||||
try {
|
||||
result = await custom(icon);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (typeof result === 'string') {
|
||||
return await getCustomIcon(
|
||||
() => result,
|
||||
() => result as string,
|
||||
collection,
|
||||
icon,
|
||||
options
|
||||
@ -42,6 +49,4 @@ export const loadIcon: UniversalIconLoader = async (
|
||||
return await getCustomIcon(custom, collection, icon, options);
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user