Fix being returned to the main menu when inventory full (!251)

- Add a new method of sending errors back but not flagging the response as failed in ItemEventCallback
- Don't treat `NOTENOUGHSPACE` errors as critical errors
- Return proper `NOTENOUGHSPACE` error code for stash space issues for trader/flea/craft
- Add missing error codes to `BackendErrorCodes`

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/251
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-03-08 08:59:14 +00:00 committed by chomp
parent d4ee8f64d4
commit 77bc22f27e
4 changed files with 42 additions and 5 deletions

View File

@ -24,17 +24,38 @@ export class ItemEventCallbacks
): IGetBodyResponseData<IItemEventRouterResponse>
{
const eventResponse = this.itemEventRouter.handleEvents(info, sessionID);
const result = (eventResponse.warnings.length > 0)
const result = (this.isCriticalError(eventResponse.warnings))
? this.httpResponse.getBody(
eventResponse,
this.getErrorCode(eventResponse.warnings),
eventResponse.warnings[0].errmsg,
) // TODO: map 228 to its enum value
)
: this.httpResponse.getBody(eventResponse);
return result;
}
/**
* Return true if the passed in list of warnings contains critical issues
* @param warnings The list of warnings to check for critical errors
* @returns
*/
private isCriticalError(warnings: Warning[]): boolean
{
// List of non-critical error codes, we return true if any error NOT included is passed in
const nonCriticalErrorCodes: BackendErrorCodes[] = [BackendErrorCodes.NOTENOUGHSPACE];
for (const warning of warnings)
{
if (!nonCriticalErrorCodes.includes(+warning.code))
{
return true;
}
}
return false;
}
protected getErrorCode(warnings: Warning[]): number
{
if (warnings[0]?.code)

View File

@ -35,6 +35,7 @@ import { IRecordShootingRangePoints } from "@spt-aki/models/eft/hideout/IRecordS
import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest";
import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { HideoutAreas } from "@spt-aki/models/enums/HideoutAreas";
import { SkillTypes } from "@spt-aki/models/enums/SkillTypes";
@ -949,7 +950,11 @@ export class HideoutController
const totalResultItems = toolsToSendToPlayer.concat(itemAndChildrenToSendToPlayer);
if (!this.inventoryHelper.canPlaceItemsInInventory(sessionID, totalResultItems))
{
this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space"));
this.httpResponse.appendErrorToOutput(
output,
this.localisationService.getText("inventory-no_stash_space"),
BackendErrorCodes.NOTENOUGHSPACE,
);
return;
}

View File

@ -20,6 +20,7 @@ import { IInventoryRemoveRequestData } from "@spt-aki/models/eft/inventory/IInve
import { IInventorySplitRequestData } from "@spt-aki/models/eft/inventory/IInventorySplitRequestData";
import { IInventoryTransferRequestData } from "@spt-aki/models/eft/inventory/IInventoryTransferRequestData";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes";
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
import { BonusType } from "@spt-aki/models/enums/BonusType";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
@ -88,7 +89,11 @@ export class InventoryHelper
if (!this.canPlaceItemsInInventory(sessionId, request.itemsWithModsToAdd))
{
// No space, exit
this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space"));
this.httpResponse.appendErrorToOutput(
output,
this.localisationService.getText("inventory-no_stash_space"),
BackendErrorCodes.NOTENOUGHSPACE,
);
return;
}
@ -470,7 +475,11 @@ export class InventoryHelper
}
else
{
this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space"));
this.httpResponse.appendErrorToOutput(
output,
this.localisationService.getText("inventory-no_stash_space"),
BackendErrorCodes.NOTENOUGHSPACE,
);
return;
}

View File

@ -63,6 +63,7 @@ export enum BackendErrorCodes
BANNEDERRORCODE = 1513,
INSUFFICIENTNUMBERINSTOCK = 1516,
TOOMANYITEMSTOSELL = 1517,
INCORRECTCLIENTPRICE = 1519,
EXAMINATIONFAILED = 22001,
ITEMALREADYEXAMINED = 22002,
UNKNOWNNGINXERROR = 9000,
@ -83,4 +84,5 @@ export enum BackendErrorCodes
PLAYERALREADYLOOKINGFORGAME = 503001,
PLAYERINRAID = 503002,
LIMITFORPRESETSREACHED = 504001,
PLAYERPROFILENOTFOUND = 505001,
}