chore: fix duplication in error paths

This commit is contained in:
Sainan 2025-01-03 08:48:40 +01:00
parent dd6b7ee4ef
commit f0be16b023
8 changed files with 3 additions and 23 deletions

View File

@ -30,13 +30,11 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
recipe => recipe._id?.toString() === claimCompletedRecipeRequest.RecipeIds[0].$oid
);
if (!pendingRecipe) {
logger.error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`);
throw new Error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`);
}
//check recipe is indeed ready to be completed
// if (pendingRecipe.CompletionDate > new Date()) {
// logger.error(`recipe ${pendingRecipe._id} is not ready to be completed`);
// throw new Error(`recipe ${pendingRecipe._id} is not ready to be completed`);
// }
@ -45,7 +43,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
const recipe = getRecipe(pendingRecipe.ItemType);
if (!recipe) {
logger.error(`no completed item found for recipe ${pendingRecipe._id.toString()}`);
throw new Error(`no completed item found for recipe ${pendingRecipe._id.toString()}`);
}

View File

@ -5,7 +5,6 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
import { getPersonalRooms } from "@/src/services/personalRoomsService";
import { getShip } from "@/src/services/shipService";
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
import { logger } from "@/src/utils/logger";
import { toOid } from "@/src/helpers/inventoryHelpers";
import { IGetShipResponse } from "@/src/types/shipTypes";
import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
@ -44,8 +43,7 @@ export const getLoadout = async (accountId: string) => {
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
if (!loadout) {
logger.error(`loadout not found for account ${accountId}`);
throw new Error("loadout not found");
throw new Error(`loadout not found for account ${accountId}`);
}
return loadout;

View File

@ -22,7 +22,6 @@ export const startRecipeController: RequestHandler = async (req, res) => {
const recipe = getRecipe(recipeName);
if (!recipe) {
logger.error(`unknown recipe ${recipeName}`);
throw new Error(`unknown recipe ${recipeName}`);
}

View File

@ -1,5 +1,4 @@
import { getIndexAfter } from "@/src/helpers/stringHelpers";
import { logger } from "@/src/utils/logger";
import {
dict_de,
dict_en,
@ -54,7 +53,6 @@ export const getWeaponType = (weaponName: string): WeaponTypeInternal => {
const weaponType = weaponInfo.productCategory;
if (!weaponType) {
logger.error(`unknown weapon category for item ${weaponName}`);
throw new Error(`unknown weapon category for item ${weaponName}`);
}
@ -83,7 +81,6 @@ export const getItemCategoryByUniqueName = (uniqueName: string): string => {
const index = getIndexAfter(uniqueName, splitWord);
if (index === -1) {
logger.error(`error parsing item category ${uniqueName}`);
throw new Error(`error parsing item category ${uniqueName}`);
}
const category = uniqueName.substring(index).split("/")[0];

View File

@ -1,12 +1,10 @@
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
import { logger } from "@/src/utils/logger";
export const getLoadout = async (accountId: string) => {
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
if (!loadout) {
logger.error(`loadout not found for account ${accountId}`);
throw new Error("loadout not found");
throw new Error(`loadout not found for account ${accountId}`);
}
return loadout;

View File

@ -1,12 +1,10 @@
import { PersonalRooms } from "@/src/models/personalRoomsModel";
import { logger } from "@/src/utils/logger";
export const getPersonalRooms = async (accountId: string) => {
const personalRooms = await PersonalRooms.findOne({ personalRoomsOwnerId: accountId });
if (!personalRooms) {
logger.error(`personal rooms not found for account ${accountId}`);
throw new Error("personal rooms not found");
throw new Error(`personal rooms not found for account ${accountId}`);
}
return personalRooms;
};

View File

@ -47,7 +47,6 @@ export const handleSetShipDecorations = async (
const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
if (!roomToPlaceIn) {
logger.error("room not found");
throw new Error("room not found");
}
@ -59,7 +58,6 @@ export const handleSetShipDecorations = async (
);
if (existingDecorationIndex === -1) {
logger.error("decoration to be moved not found");
throw new Error("decoration to be moved not found");
}
@ -143,13 +141,11 @@ export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlaced
const room = personalRooms.Ship.Rooms.find(room => room.Name === req.Room);
if (!room) {
logger.error("room not found");
throw new Error("room not found");
}
const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId);
if (!placedDeco) {
logger.error("deco not found");
throw new Error("deco not found");
}

View File

@ -1,6 +1,5 @@
import { Ship } from "@/src/models/shipModel";
import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
import { logger } from "@/src/utils/logger";
import { Types } from "mongoose";
export const createShip = async (
@ -26,7 +25,6 @@ export const getShip = async (shipId: Types.ObjectId, fieldSelection: string = "
const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
if (!ship) {
logger.error(`error finding a ship with id ${shipId.toString()}`);
throw new Error(`error finding a ship with id ${shipId.toString()}`);
}
@ -39,7 +37,6 @@ export const getShipLean = async (shipOwnerId: string) => {
}>("LoadOutInventory.LoadOutPresets");
if (!ship) {
logger.error(`error finding a ship for account ${shipOwnerId}`);
throw new Error(`error finding a ship for account ${shipOwnerId}`);
}