Better error handling in server

This commit is contained in:
Tyfon
2024-07-29 13:24:20 -07:00
parent 14dd7c7ad2
commit 54812d4a03

View File

@@ -40,11 +40,15 @@ class UIFixes implements IPreSptLoadMod {
original.call(inRaidHelper, pmcData, sessionId);
// Restore the quickbinds for items that still exist
try {
for (const index in fastPanel) {
if (pmcData.Inventory.items.find(i => i._id == fastPanel[index])) {
pmcData.Inventory.fastPanel[index] = fastPanel[index];
}
}
} catch (error) {
this.logger.error(`UIFixes failed to restore quickbinds\n ${error}`);
}
};
},
{ frequency: "Always" }
@@ -61,15 +65,21 @@ class UIFixes implements IPreSptLoadMod {
const result = original.call(hideoutHelper, pmcData, body, sessionID);
// The items haven't been deleted yet, augment the list with their parentId
try {
const bodyAsSingle = body as IHideoutSingleProductionStartRequestData;
if (bodyAsSingle && bodyAsSingle.tools?.length > 0) {
const requestTools = bodyAsSingle.tools;
const tools = pmcData.Hideout.Production[body.recipeId].sptRequiredTools;
for (let i = 0; i < tools.length; i++) {
const originalTool = pmcData.Inventory.items.find(x => x._id === requestTools[i].id);
const originalTool = pmcData.Inventory.items.find(
x => x._id === requestTools[i].id
);
tools[i]["uifixes.returnTo"] = [originalTool.parentId, originalTool.slotId];
}
}
} catch (error) {
this.logger.error(`UIFixes failed to save tool origin\n ${error}`);
}
return result;
};
@@ -89,11 +99,13 @@ class UIFixes implements IPreSptLoadMod {
// If a tool marked with uifixes is there, try to return it to its original container
const tool = itemWithModsToAddClone[0];
if (tool["uifixes.returnTo"]) {
try {
const [containerId, slotId] = tool["uifixes.returnTo"];
const container = pmcData.Inventory.items.find(x => x._id === containerId);
if (container) {
const containerTemplate = itemHelper.getItem(container._tpl)[1];
const [foundTemplate, containerTemplate] = itemHelper.getItem(container._tpl);
if (foundTemplate && containerTemplate) {
const containerFS2D = inventoryHelper.getContainerMap(
containerTemplate._props.Grids[0]._props.cellsH,
containerTemplate._props.Grids[0]._props.cellsV,
@@ -136,6 +148,12 @@ class UIFixes implements IPreSptLoadMod {
}
}
}
} catch (error) {
this.logger.error(
`UIFixes failed to put a tool back, it will be returned to your stash as normal.\n ${error}`
);
}
}
return original.call(inventoryHelper, sessionId, request, pmcData, output);
};