/**
* Loads resources from HTTP responses for non-production use with verbose logging.
*
* @param {string} url The URL to load.
* @param {object} options Optional configuration.
* @param {boolean} options.production Whether this is a production environment (default: false).
*/
async function loadResource(url, options = {}) {
const { production = false } = options;
if (production) {
console.warn(`Skipping resource load for ${url} in production environment.`);
return;
}
console.debug(`Loading resource from ${url}...`);
try {
const response = await fetch(url);
if (!response.ok) {
console.error(`HTTP error! Status: ${response.status} for ${url}`);
return;
}
const contentType = response.headers.get('content-type');
console.debug(`Content type: ${contentType}`);
const data = await response.text(); // Or response.json(), response.blob(), etc. depending on the resource
console.debug(`Successfully loaded resource from ${url}.`);
return data;
} catch (error) {
console.error(`Error loading resource from ${url}:`, error);
}
}
export default loadResource;
Add your comment