chore: fix duplication in error paths
This commit is contained in:
parent
dd6b7ee4ef
commit
f0be16b023
@ -30,13 +30,11 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
recipe => recipe._id?.toString() === claimCompletedRecipeRequest.RecipeIds[0].$oid
|
recipe => recipe._id?.toString() === claimCompletedRecipeRequest.RecipeIds[0].$oid
|
||||||
);
|
);
|
||||||
if (!pendingRecipe) {
|
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}`);
|
throw new Error(`no pending recipe found with id ${claimCompletedRecipeRequest.RecipeIds[0].$oid}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check recipe is indeed ready to be completed
|
//check recipe is indeed ready to be completed
|
||||||
// if (pendingRecipe.CompletionDate > new Date()) {
|
// 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`);
|
// 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);
|
const recipe = getRecipe(pendingRecipe.ItemType);
|
||||||
if (!recipe) {
|
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()}`);
|
throw new Error(`no completed item found for recipe ${pendingRecipe._id.toString()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
|
|||||||
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||||
import { getShip } from "@/src/services/shipService";
|
import { getShip } from "@/src/services/shipService";
|
||||||
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
|
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||||
import { IGetShipResponse } from "@/src/types/shipTypes";
|
import { IGetShipResponse } from "@/src/types/shipTypes";
|
||||||
import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
|
import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
|
||||||
@ -44,8 +43,7 @@ export const getLoadout = async (accountId: string) => {
|
|||||||
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
|
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
|
||||||
|
|
||||||
if (!loadout) {
|
if (!loadout) {
|
||||||
logger.error(`loadout not found for account ${accountId}`);
|
throw new Error(`loadout not found for account ${accountId}`);
|
||||||
throw new Error("loadout not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadout;
|
return loadout;
|
||||||
|
@ -22,7 +22,6 @@ export const startRecipeController: RequestHandler = async (req, res) => {
|
|||||||
const recipe = getRecipe(recipeName);
|
const recipe = getRecipe(recipeName);
|
||||||
|
|
||||||
if (!recipe) {
|
if (!recipe) {
|
||||||
logger.error(`unknown recipe ${recipeName}`);
|
|
||||||
throw new Error(`unknown recipe ${recipeName}`);
|
throw new Error(`unknown recipe ${recipeName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { getIndexAfter } from "@/src/helpers/stringHelpers";
|
import { getIndexAfter } from "@/src/helpers/stringHelpers";
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
import {
|
import {
|
||||||
dict_de,
|
dict_de,
|
||||||
dict_en,
|
dict_en,
|
||||||
@ -54,7 +53,6 @@ export const getWeaponType = (weaponName: string): WeaponTypeInternal => {
|
|||||||
const weaponType = weaponInfo.productCategory;
|
const weaponType = weaponInfo.productCategory;
|
||||||
|
|
||||||
if (!weaponType) {
|
if (!weaponType) {
|
||||||
logger.error(`unknown weapon category for item ${weaponName}`);
|
|
||||||
throw new 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);
|
const index = getIndexAfter(uniqueName, splitWord);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
logger.error(`error parsing item category ${uniqueName}`);
|
|
||||||
throw new Error(`error parsing item category ${uniqueName}`);
|
throw new Error(`error parsing item category ${uniqueName}`);
|
||||||
}
|
}
|
||||||
const category = uniqueName.substring(index).split("/")[0];
|
const category = uniqueName.substring(index).split("/")[0];
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
|
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
|
|
||||||
export const getLoadout = async (accountId: string) => {
|
export const getLoadout = async (accountId: string) => {
|
||||||
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
|
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
|
||||||
|
|
||||||
if (!loadout) {
|
if (!loadout) {
|
||||||
logger.error(`loadout not found for account ${accountId}`);
|
throw new Error(`loadout not found for account ${accountId}`);
|
||||||
throw new Error("loadout not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadout;
|
return loadout;
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import { PersonalRooms } from "@/src/models/personalRoomsModel";
|
import { PersonalRooms } from "@/src/models/personalRoomsModel";
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
|
|
||||||
export const getPersonalRooms = async (accountId: string) => {
|
export const getPersonalRooms = async (accountId: string) => {
|
||||||
const personalRooms = await PersonalRooms.findOne({ personalRoomsOwnerId: accountId });
|
const personalRooms = await PersonalRooms.findOne({ personalRoomsOwnerId: accountId });
|
||||||
|
|
||||||
if (!personalRooms) {
|
if (!personalRooms) {
|
||||||
logger.error(`personal rooms not found for account ${accountId}`);
|
throw new Error(`personal rooms not found for account ${accountId}`);
|
||||||
throw new Error("personal rooms not found");
|
|
||||||
}
|
}
|
||||||
return personalRooms;
|
return personalRooms;
|
||||||
};
|
};
|
||||||
|
@ -47,7 +47,6 @@ export const handleSetShipDecorations = async (
|
|||||||
const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
|
const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
|
||||||
|
|
||||||
if (!roomToPlaceIn) {
|
if (!roomToPlaceIn) {
|
||||||
logger.error("room not found");
|
|
||||||
throw new Error("room not found");
|
throw new Error("room not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +58,6 @@ export const handleSetShipDecorations = async (
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (existingDecorationIndex === -1) {
|
if (existingDecorationIndex === -1) {
|
||||||
logger.error("decoration to be moved not found");
|
|
||||||
throw new 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);
|
const room = personalRooms.Ship.Rooms.find(room => room.Name === req.Room);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
logger.error("room not found");
|
|
||||||
throw new Error("room not found");
|
throw new Error("room not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId);
|
const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId);
|
||||||
if (!placedDeco) {
|
if (!placedDeco) {
|
||||||
logger.error("deco not found");
|
|
||||||
throw new Error("deco not found");
|
throw new Error("deco not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Ship } from "@/src/models/shipModel";
|
import { Ship } from "@/src/models/shipModel";
|
||||||
import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
|
import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
export const createShip = async (
|
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);
|
const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
|
||||||
|
|
||||||
if (!ship) {
|
if (!ship) {
|
||||||
logger.error(`error finding a ship with id ${shipId.toString()}`);
|
|
||||||
throw new 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");
|
}>("LoadOutInventory.LoadOutPresets");
|
||||||
|
|
||||||
if (!ship) {
|
if (!ship) {
|
||||||
logger.error(`error finding a ship for account ${shipOwnerId}`);
|
|
||||||
throw new Error(`error finding a ship for account ${shipOwnerId}`);
|
throw new Error(`error finding a ship for account ${shipOwnerId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user