From f0be16b0237db0dfc18340215f84edd904be4f85 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 3 Jan 2025 08:48:40 +0100 Subject: [PATCH] chore: fix duplication in error paths --- src/controllers/api/claimCompletedRecipeController.ts | 3 --- src/controllers/api/getShipController.ts | 4 +--- src/controllers/api/startRecipeController.ts | 1 - src/services/itemDataService.ts | 3 --- src/services/loadoutService.ts | 4 +--- src/services/personalRoomsService.ts | 4 +--- src/services/shipCustomizationsService.ts | 4 ---- src/services/shipService.ts | 3 --- 8 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/controllers/api/claimCompletedRecipeController.ts b/src/controllers/api/claimCompletedRecipeController.ts index 237a5b87..c0d2fdc0 100644 --- a/src/controllers/api/claimCompletedRecipeController.ts +++ b/src/controllers/api/claimCompletedRecipeController.ts @@ -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()}`); } diff --git a/src/controllers/api/getShipController.ts b/src/controllers/api/getShipController.ts index 4dad54a8..3ce7a6c3 100644 --- a/src/controllers/api/getShipController.ts +++ b/src/controllers/api/getShipController.ts @@ -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; diff --git a/src/controllers/api/startRecipeController.ts b/src/controllers/api/startRecipeController.ts index 20693509..83501874 100644 --- a/src/controllers/api/startRecipeController.ts +++ b/src/controllers/api/startRecipeController.ts @@ -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}`); } diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index f45f759b..df3e2b78 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -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]; diff --git a/src/services/loadoutService.ts b/src/services/loadoutService.ts index 37f91612..f9c385c5 100644 --- a/src/services/loadoutService.ts +++ b/src/services/loadoutService.ts @@ -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; diff --git a/src/services/personalRoomsService.ts b/src/services/personalRoomsService.ts index c2d0b629..1392ce46 100644 --- a/src/services/personalRoomsService.ts +++ b/src/services/personalRoomsService.ts @@ -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; }; diff --git a/src/services/shipCustomizationsService.ts b/src/services/shipCustomizationsService.ts index ddf70f59..26aef04e 100644 --- a/src/services/shipCustomizationsService.ts +++ b/src/services/shipCustomizationsService.ts @@ -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"); } diff --git a/src/services/shipService.ts b/src/services/shipService.ts index f654721d..0925a409 100644 --- a/src/services/shipService.ts +++ b/src/services/shipService.ts @@ -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}`); }