mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 17:19:30 -07:00
Improve error handling to help prevent runtime errors
Adds input validation and safe property access to utility functions to handle edge cases and invalid arguments gracefully
This commit is contained in:
@@ -5,6 +5,11 @@ import { blob } from './fetch.mjs';
|
||||
// a list of cached icons is used to avoid hitting the cache multiple times
|
||||
const cachedImages = [];
|
||||
const preloadImg = (src) => {
|
||||
if (!src || typeof src !== 'string') {
|
||||
console.warn(`preloadImg expects a URL string, received: '${src}' (${typeof src})`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cachedImages.includes(src)) return false;
|
||||
blob(src);
|
||||
cachedImages.push(src);
|
||||
|
||||
Reference in New Issue
Block a user