Skip to content

Build your personal knowledge base with Trilium Notes

chore(routes): fix no-explicit-any lint/ts error for catch blocks

Panagiotis Papadopoulose3d0c53d039a
diff --git a/src/routes/api/script.ts b/src/routes/api/script.ts
index 6907a5d9c8..a289dc565d 100644
--- a/src/routes/api/script.ts
+++ b/src/routes/api/script.ts
@@ -33,8 +33,11 @@ async function exec(req: Request) {
executionResult: result,
maxEntityChangeId: syncService.getMaxEntityChangeId()
};
- } catch (e: any) {
- return { success: false, error: e.message };
+ } catch (e: unknown) {
+ return {
+ success: false,
+ error: (e instanceof Error) ? e.message : "Unknown Error"
+ };
}
}
diff --git a/src/routes/api/sql.ts b/src/routes/api/sql.ts
index ed440f42d4..a9876b6572 100644
--- a/src/routes/api/sql.ts
+++ b/src/routes/api/sql.ts
@@ -56,10 +56,10 @@ function execute(req: Request) {
success: true,
results
};
- } catch (e: any) {
+ } catch (e: unknown) {
return {
success: false,
- error: e.message
+ error: (e instanceof Error) ? e.message : "Unknown Error"
};
}
}
diff --git a/src/routes/api/sync.ts b/src/routes/api/sync.ts
index 736e1e97bf..8e186f92a7 100644
--- a/src/routes/api/sync.ts
+++ b/src/routes/api/sync.ts
@@ -30,10 +30,10 @@ async function testSync() {
syncService.sync();
return { success: true, message: t("test_sync.successful") };
- } catch (e: any) {
+ } catch (e: unknown) {
return {
success: false,
- message: e.message
+ error: (e instanceof Error) ? e.message : "Unknown Error"
};
}
}
diff --git a/src/routes/assets.ts b/src/routes/assets.ts
index 37585d8d7c..a26c226855 100644
--- a/src/routes/assets.ts
+++ b/src/routes/assets.ts
@@ -5,7 +5,7 @@ import express from "express";
import { isDev, isElectron } from "../services/utils.js";
import type serveStatic from "serve-static";
-const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOptions<express.Response<any, Record<string, any>>>) => {
+const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOptions<express.Response<unknown, Record<string, unknown>>>) => {
if (!isDev) {
options = {
maxAge: "1y",
diff --git a/src/routes/routes.ts b/src/routes/routes.ts
index ad1850aca1..227b10d3c9 100644
--- a/src/routes/routes.ts
+++ b/src/routes/routes.ts
@@ -477,7 +477,7 @@ function route(method: HttpMethod, path: string, middleware: express.Handler[],
if (result?.then) {
// promise
- result.then((promiseResult: unknown) => handleResponse(resultHandler, req, res, promiseResult, start)).catch((e: any) => handleException(e, method, path, res));
+ result.then((promiseResult: unknown) => handleResponse(resultHandler, req, res, promiseResult, start)).catch((e: unknown) => handleException(e, method, path, res));
} else {
handleResponse(resultHandler, req, res, result, start);
}