aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-02 18:15:41 +0200
committerChocobozzz <me@florianbigard.com>2021-06-02 18:15:41 +0200
commite030bfb59dd5ee65f20a64686ec9b22ca39f70ae (patch)
treec9a439159ef540291e3c030bcaf958b953442147 /server.ts
parent463206948d6a9d46e7e68d55c7b763e601ecc870 (diff)
downloadPeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.tar.gz
PeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.tar.zst
PeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.zip
Refactor server errors handler
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts7
1 files changed, 4 insertions, 3 deletions
diff --git a/server.ts b/server.ts
index 66c9173ca..2caee18e7 100644
--- a/server.ts
+++ b/server.ts
@@ -106,6 +106,7 @@ import {
106 downloadRouter 106 downloadRouter
107} from './server/controllers' 107} from './server/controllers'
108import { advertiseDoNotTrack } from './server/middlewares/dnt' 108import { advertiseDoNotTrack } from './server/middlewares/dnt'
109import { apiFailMiddleware } from './server/middlewares/error'
109import { Redis } from './server/lib/redis' 110import { Redis } from './server/lib/redis'
110import { ActorFollowScheduler } from './server/lib/schedulers/actor-follow-scheduler' 111import { ActorFollowScheduler } from './server/lib/schedulers/actor-follow-scheduler'
111import { RemoveOldViewsScheduler } from './server/lib/schedulers/remove-old-views-scheduler' 112import { RemoveOldViewsScheduler } from './server/lib/schedulers/remove-old-views-scheduler'
@@ -127,7 +128,6 @@ import { LiveManager } from './server/lib/live-manager'
127import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes' 128import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes'
128import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' 129import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
129import { ServerConfigManager } from '@server/lib/server-config-manager' 130import { ServerConfigManager } from '@server/lib/server-config-manager'
130import { apiResponseHelpers } from '@server/helpers/express-utils'
131 131
132// ----------- Command line ----------- 132// ----------- Command line -----------
133 133
@@ -169,8 +169,8 @@ app.use(morgan('combined', {
169 skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping' 169 skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping'
170})) 170}))
171 171
172// Response helpers used for errors 172// Add .fail() helper to response
173app.use(apiResponseHelpers) 173app.use(apiFailMiddleware)
174 174
175// For body requests 175// For body requests
176app.use(express.urlencoded({ extended: false })) 176app.use(express.urlencoded({ extended: false }))
@@ -179,6 +179,7 @@ app.use(express.json({
179 limit: '500kb', 179 limit: '500kb',
180 verify: (req: express.Request, res: express.Response, buf: Buffer) => { 180 verify: (req: express.Request, res: express.Response, buf: Buffer) => {
181 const valid = isHTTPSignatureDigestValid(buf, req) 181 const valid = isHTTPSignatureDigestValid(buf, req)
182
182 if (valid !== true) { 183 if (valid !== true) {
183 res.fail({ 184 res.fail({
184 status: HttpStatusCode.FORBIDDEN_403, 185 status: HttpStatusCode.FORBIDDEN_403,