aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-06-01 01:36:53 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-02 16:57:07 +0200
commit76148b27f7501bac061992136852be4303370c8d (patch)
treefc0559253e833c9252fa14ebaec5321d88bfb4e8 /server.ts
parent5ed25fb76e920dac364cb9ef46f14ec4bd372949 (diff)
downloadPeerTube-76148b27f7501bac061992136852be4303370c8d.tar.gz
PeerTube-76148b27f7501bac061992136852be4303370c8d.tar.zst
PeerTube-76148b27f7501bac061992136852be4303370c8d.zip
refactor API errors to standard error format
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts10
1 files changed, 9 insertions, 1 deletions
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'
128import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes' 128import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes'
129import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' 129import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
130import { ServerConfigManager } from '@server/lib/server-config-manager' 130import { ServerConfigManager } from '@server/lib/server-config-manager'
131import { apiResponseHelpers } from '@server/helpers/express-utils'
131 132
132// ----------- Command line ----------- 133// ----------- Command line -----------
133 134
@@ -186,6 +187,9 @@ app.use(cookieParser())
186// W3C DNT Tracking Status 187// W3C DNT Tracking Status
187app.use(advertiseDoNotTrack) 188app.use(advertiseDoNotTrack)
188 189
190// Response helpers used in developement
191app.use(apiResponseHelpers)
192
189// ----------- Views, routes and static files ----------- 193// ----------- Views, routes and static files -----------
190 194
191// API 195// API
@@ -235,7 +239,11 @@ app.use(function (err, req, res, next) {
235 const sql = err.parent ? err.parent.sql : undefined 239 const sql = err.parent ? err.parent.sql : undefined
236 240
237 logger.error('Error in controller.', { err: error, sql }) 241 logger.error('Error in controller.', { err: error, sql })
238 return res.status(err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500).end() 242 return res.fail({
243 status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
244 message: err.message,
245 type: err.name
246 })
239}) 247})
240 248
241const server = createWebsocketTrackerServer(app) 249const server = createWebsocketTrackerServer(app)