diff --git a/src/share/routes.spec.ts b/src/share/routes.spec.ts index 86e1927bd..5072bb297 100644 --- a/src/share/routes.spec.ts +++ b/src/share/routes.spec.ts @@ -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++; } diff --git a/src/share/routes.ts b/src/share/routes.ts index 3c6db87d5..db7e62f40 100644 --- a/src/share/routes.ts +++ b/src/share/routes.ts @@ -15,7 +15,7 @@ import log from "../services/log.js"; import type SNote from "./shaca/entities/snote.js"; import type SBranch from "./shaca/entities/sbranch.js"; import type SAttachment from "./shaca/entities/sattachment.js"; -import utils from "../services/utils.js"; +import utils, { safeExtractMessageAndStackFromError } from "../services/utils.js"; import options from "../services/options.js"; function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } { @@ -183,8 +183,9 @@ function register(router: Router) { res.send(ejsResult); useDefaultView = false; // Rendering went okay, don't use default view } - } catch (e: any) { - log.error(`Rendering user provided share template (${templateId}) threw exception ${e.message} with stacktrace: ${e.stack}`); + } catch (e: unknown) { + const [errMessage, errStack] = safeExtractMessageAndStackFromError(e); + log.error(`Rendering user provided share template (${templateId}) threw exception ${errMessage} with stacktrace: ${errStack}`); } } }