chore(share): use safeExtractMessageAndStackFromError to get rid of "any" in try/catch blocks

This commit is contained in:
Panagiotis Papadopoulos
2025-03-10 07:15:43 +01:00
parent a778ec617f
commit bdc829198c
2 changed files with 8 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import { beforeAll, beforeEach, describe, expect, it } from "vitest";
import supertest from "supertest";
import { initializeTranslations } from "../services/i18n.js";
import type { Application, Request, Response, NextFunction } from "express";
import { safeExtractMessageAndStackFromError } from "../services/utils.js";
let app: Application;
@@ -11,8 +12,9 @@ describe("Share API test", () => {
beforeAll(async () => {
initializeTranslations();
app = (await import("../app.js")).default;
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
if (err.message.includes("Cannot set headers after they are sent to the client")) {
app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {
const [errMessage] = safeExtractMessageAndStackFromError(err)
if (errMessage.includes("Cannot set headers after they are sent to the client")) {
cannotSetHeadersCount++;
}