🆙 Update better error handeling

This commit is contained in:
duckietm
2026-03-19 09:40:49 +01:00
parent b47ac17a46
commit 5b139dfef8
9 changed files with 240 additions and 70 deletions
@@ -18,13 +18,31 @@ export class FurnitureDataLoader
{
const url = GetConfiguration().getValue<string>('furnidata.url');
if(!url || !url.length) throw new Error('invalid furni data url');
if(!url || !url.length) throw new Error('Missing "furnidata.url" in config — add the furniture data URL to your renderer-config.json');
const response = await fetch(url);
let response: Response;
if(response.status !== 200) throw new Error('Invalid furni data file');
try
{
response = await fetch(url);
}
catch(fetchErr)
{
throw new Error(`Could not fetch furniture data from "${ url }" — check "furnidata.url" in renderer-config.json (${ fetchErr.message })`);
}
const responseData = await response.json();
if(response.status !== 200) throw new Error(`Failed to load furniture data from "${ url }" — server returned HTTP ${ response.status }. Check "furnidata.url" in renderer-config.json`);
let responseData: any;
try
{
responseData = await response.json();
}
catch(parseErr)
{
throw new Error(`Invalid JSON in furniture data "${ url }" — the URL may be wrong. Check "furnidata.url" in renderer-config.json (${ parseErr.message })`);
}
if(responseData.roomitemtypes) this.parseFloorItems(responseData.roomitemtypes);
@@ -15,13 +15,31 @@ export class ProductDataLoader
{
const url = GetConfiguration().getValue<string>('productdata.url');
if(!url || !url.length) throw new Error('invalid product data url');
if(!url || !url.length) throw new Error('Missing "productdata.url" in config — add the product data URL to your renderer-config.json');
const response = await fetch(url);
let response: Response;
if(response.status !== 200) throw new Error('Invalid product data file');
try
{
response = await fetch(url);
}
catch(fetchErr)
{
throw new Error(`Could not fetch product data from "${ url }" — check "productdata.url" in renderer-config.json (${ fetchErr.message })`);
}
const responseData = await response.json();
if(response.status !== 200) throw new Error(`Failed to load product data from "${ url }" — server returned HTTP ${ response.status }. Check "productdata.url" in renderer-config.json`);
let responseData: any;
try
{
responseData = await response.json();
}
catch(parseErr)
{
throw new Error(`Invalid JSON in product data "${ url }" — the URL may be wrong. Check "productdata.url" in renderer-config.json (${ parseErr.message })`);
}
this.parseProducts(responseData.productdata);
}