fix: handle 'Invalid accountId-nonce pair' error for all controllers

This commit is contained in:
Sainan 2025-01-03 08:44:19 +01:00
parent 28926d1d30
commit dd6b7ee4ef
2 changed files with 4 additions and 8 deletions

View File

@ -18,13 +18,7 @@ import {
import { handleSubsumeCompletion } from "./infestedFoundryController"; import { handleSubsumeCompletion } from "./infestedFoundryController";
export const inventoryController: RequestHandler = async (request, response) => { export const inventoryController: RequestHandler = async (request, response) => {
let account; const account = await getAccountForRequest(request);
try {
account = await getAccountForRequest(request);
} catch (e) {
response.status(400).send("Log-in expired");
return;
}
const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() }) const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
.populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets") .populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")

View File

@ -2,7 +2,9 @@ import { NextFunction, Request, Response } from "express";
import { logger } from "../utils/logger"; import { logger } from "../utils/logger";
export const errorHandler = (err: Error, req: Request, res: Response, _next: NextFunction): void => { export const errorHandler = (err: Error, req: Request, res: Response, _next: NextFunction): void => {
if (err.stack) { if (err.message == "Invalid accountId-nonce pair") {
res.status(400).json("Log-in expired");
} else if (err.stack) {
const stackArr = err.stack.split("\n"); const stackArr = err.stack.split("\n");
stackArr[0] += ` while processing ${req.path} request`; stackArr[0] += ` while processing ${req.path} request`;
logger.error(stackArr.join("\n")); logger.error(stackArr.join("\n"));