mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-01 18:31:31 +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 supertest from "supertest";
|
||||||
import { initializeTranslations } from "../services/i18n.js";
|
import { initializeTranslations } from "../services/i18n.js";
|
||||||
import type { Application, Request, Response, NextFunction } from "express";
|
import type { Application, Request, Response, NextFunction } from "express";
|
||||||
|
import { safeExtractMessageAndStackFromError } from "../services/utils.js";
|
||||||
|
|
||||||
let app: Application;
|
let app: Application;
|
||||||
|
|
||||||
@ -11,8 +12,9 @@ describe("Share API test", () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
initializeTranslations();
|
initializeTranslations();
|
||||||
app = (await import("../app.js")).default;
|
app = (await import("../app.js")).default;
|
||||||
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
|
app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {
|
||||||
if (err.message.includes("Cannot set headers after they are sent to the client")) {
|
const [errMessage] = safeExtractMessageAndStackFromError(err)
|
||||||
|
if (errMessage.includes("Cannot set headers after they are sent to the client")) {
|
||||||
cannotSetHeadersCount++;
|
cannotSetHeadersCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import log from "../services/log.js";
|
|||||||
import type SNote from "./shaca/entities/snote.js";
|
import type SNote from "./shaca/entities/snote.js";
|
||||||
import type SBranch from "./shaca/entities/sbranch.js";
|
import type SBranch from "./shaca/entities/sbranch.js";
|
||||||
import type SAttachment from "./shaca/entities/sattachment.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";
|
import options from "../services/options.js";
|
||||||
|
|
||||||
function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } {
|
function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } {
|
||||||
@ -183,8 +183,9 @@ function register(router: Router) {
|
|||||||
res.send(ejsResult);
|
res.send(ejsResult);
|
||||||
useDefaultView = false; // Rendering went okay, don't use default view
|
useDefaultView = false; // Rendering went okay, don't use default view
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
log.error(`Rendering user provided share template (${templateId}) threw exception ${e.message} with stacktrace: ${e.stack}`);
|
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