Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server-ts: Convert routes/error_handlers
Elian Doranc2eefad28766
diff --git a/src/app.js b/src/app.jsindex ba4d2da87c..8c812dafec 100644--- a/src/app.js+++ b/src/app.js@@ -40,7 +40,7 @@ app.use(favicon(`${__dirname}/../images/app-icons/win/icon.ico`));require('./routes/assets').register(app);require('./routes/routes.js').register(app);require('./routes/custom').register(app);-require('./routes/error_handlers.js').register(app);+require('./routes/error_handlers').register(app);// triggers sync timerrequire('./services/sync');diff --git a/src/routes/error_handlers.js b/src/routes/error_handlers.tssimilarity index 73%rename from src/routes/error_handlers.jsrename to src/routes/error_handlers.tsindex 4d17b0d5d9..96d326bd9c 100644--- a/src/routes/error_handlers.js+++ b/src/routes/error_handlers.ts@@ -1,7 +1,8 @@-const log = require('../services/log');+import { Application, NextFunction, Request, Response } from 'express';+import log = require('../services/log');-function register(app) {- app.use((err, req, res, next) => {+function register(app: Application) {+ app.use((err: any, req: Request, res: Response, next: NextFunction) => {if (err.code !== 'EBADCSRFTOKEN') {return next(err);}@@ -16,12 +17,12 @@ function register(app) {// catch 404 and forward to error handlerapp.use((req, res, next) => {const err = new Error(`Router not found for request ${req.method} ${req.url}`);- err.status = 404;+ (err as any).status = 404;next(err);});// error handler- app.use((err, req, res, next) => {+ app.use((err: any, req: Request, res: Response, next: NextFunction) => {if (err && err.message && ((err.message.includes("Router not found for request") && err.message.includes(".js.map"))|| (err.message.includes("Router not found for request") && err.message.includes(".css.map"))@@ -38,6 +39,6 @@ function register(app) {});}-module.exports = {+export = {register};