From 76148b27f7501bac061992136852be4303370c8d Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 1 Jun 2021 01:36:53 +0200 Subject: refactor API errors to standard error format --- server.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'server.ts') diff --git a/server.ts b/server.ts index 7aaf1e553..1834256d5 100644 --- a/server.ts +++ b/server.ts @@ -128,6 +128,7 @@ import { LiveManager } from './server/lib/live-manager' import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes' import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' import { ServerConfigManager } from '@server/lib/server-config-manager' +import { apiResponseHelpers } from '@server/helpers/express-utils' // ----------- Command line ----------- @@ -186,6 +187,9 @@ app.use(cookieParser()) // W3C DNT Tracking Status app.use(advertiseDoNotTrack) +// Response helpers used in developement +app.use(apiResponseHelpers) + // ----------- Views, routes and static files ----------- // API @@ -235,7 +239,11 @@ app.use(function (err, req, res, next) { const sql = err.parent ? err.parent.sql : undefined logger.error('Error in controller.', { err: error, sql }) - return res.status(err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500).end() + return res.fail({ + status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500, + message: err.message, + type: err.name + }) }) const server = createWebsocketTrackerServer(app) -- cgit v1.2.3