mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-01 02:01:33 +08:00
chore(share): use safeExtractMessageAndStackFromError to get rid of "any" in try/catch blocks
This commit is contained in:
parent
a778ec617f
commit
bdc829198c
@ -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++;
|
||||
}
|
||||
|
||||
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user