Enhance error handling in FalukantService: Add validation for product sellCost in calcRegionalSellPrice and getProductPriceInRegion methods, ensuring proper error messages are logged when sellCost is undefined or null.
This commit is contained in:
@@ -101,6 +101,11 @@ async function calcRegionalSellPrice(product, knowledgeFactor, regionId, worthPe
|
||||
worthPercent = townWorth?.worthPercent || 50; // Default 50% wenn nicht gefunden
|
||||
}
|
||||
|
||||
// Prüfe ob sellCost vorhanden ist
|
||||
if (product.sellCost === null || product.sellCost === undefined) {
|
||||
throw new Error(`Product ${product.id} has no sellCost defined`);
|
||||
}
|
||||
|
||||
// Basispreis basierend auf regionalem worthPercent
|
||||
const basePrice = product.sellCost * (worthPercent / 100);
|
||||
|
||||
@@ -4178,6 +4183,7 @@ class FalukantService extends BaseService {
|
||||
}
|
||||
|
||||
async getProductPriceInRegion(hashedUserId, productId, regionId) {
|
||||
try {
|
||||
const user = await this.getFalukantUserByHashedId(hashedUserId);
|
||||
const character = await FalukantCharacter.findOne({ where: { userId: user.id } });
|
||||
if (!character) {
|
||||
@@ -4190,6 +4196,11 @@ class FalukantService extends BaseService {
|
||||
throw new Error(`Product not found with id ${productId}`);
|
||||
}
|
||||
|
||||
// Prüfe ob sellCost vorhanden ist
|
||||
if (product.sellCost === null || product.sellCost === undefined) {
|
||||
throw new Error(`Product ${productId} has no sellCost defined`);
|
||||
}
|
||||
|
||||
// Knowledge für dieses Produkt abrufen
|
||||
const knowledge = await Knowledge.findOne({
|
||||
where: { characterId: character.id, productId: productId }
|
||||
@@ -4200,6 +4211,10 @@ class FalukantService extends BaseService {
|
||||
const price = await calcRegionalSellPrice(product, knowledgeFactor, regionId);
|
||||
|
||||
return { price };
|
||||
} catch (error) {
|
||||
console.error(`[getProductPriceInRegion] Error for productId=${productId}, regionId=${regionId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getProductPricesInCities(hashedUserId, productId, currentPrice, currentRegionId = null) {
|
||||
|
||||
Reference in New Issue
Block a user