diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-06-01 01:36:53 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-06-02 16:57:07 +0200 |
commit | 76148b27f7501bac061992136852be4303370c8d (patch) | |
tree | fc0559253e833c9252fa14ebaec5321d88bfb4e8 /server.ts | |
parent | 5ed25fb76e920dac364cb9ef46f14ec4bd372949 (diff) | |
download | PeerTube-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.ts | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -128,6 +128,7 @@ import { LiveManager } from './server/lib/live-manager' | |||
128 | import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes' | 128 | import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes' |
129 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' | 129 | import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' |
130 | import { ServerConfigManager } from '@server/lib/server-config-manager' | 130 | import { ServerConfigManager } from '@server/lib/server-config-manager' |
131 | import { 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 |
187 | app.use(advertiseDoNotTrack) | 188 | app.use(advertiseDoNotTrack) |
188 | 189 | ||
190 | // Response helpers used in developement | ||
191 | app.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 | ||
241 | const server = createWebsocketTrackerServer(app) | 249 | const server = createWebsocketTrackerServer(app) |