2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-22 14:48:24 +00:00

Do not spam log with errors

This commit is contained in:
Vjacheslav Trushkin 2020-06-09 20:07:48 +03:00
parent de037e43e0
commit 220190d8fe

View File

@ -112,17 +112,24 @@ function loadedNewIcons(provider: string, prefix: string): void {
} }
} }
// Storage for errors for loadNewIcons(). Used to avoid spamming log with identical errors.
const errorsCache: Record<string, number> = Object.create(null);
/** /**
* Load icons * Load icons
*/ */
function loadNewIcons(provider: string, prefix: string, icons: string[]): void { function loadNewIcons(provider: string, prefix: string, icons: string[]): void {
function err(): void { function err(): void {
console.error( const key = (provider === '' ? '' : '@' + provider + ':') + prefix;
'Unable to retrieve icons for "' + const time = Math.floor(Date.now() / 60000); // log once in a minute
(provider === '' ? '' : '@' + provider + ':') + if (errorsCache[key] < time) {
prefix + errorsCache[key] = time;
'" because API is not configured properly.' console.error(
); 'Unable to retrieve icons for "' +
key +
'" because API is not configured properly.'
);
}
} }
// Create nested objects if needed // Create nested objects if needed