aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-13 11:21:19 +0200
committerChocobozzz <me@florianbigard.com>2022-07-13 11:21:19 +0200
commitf7ce623db1225b7b6f8383c33cab9515b36907fe (patch)
tree6d940af0c1a6aa8279fcb1eb793c001c512b5755 /server/controllers
parentea8107bff8e544594716a76d30ff372fc80d755c (diff)
downloadPeerTube-f7ce623db1225b7b6f8383c33cab9515b36907fe.tar.gz
PeerTube-f7ce623db1225b7b6f8383c33cab9515b36907fe.tar.zst
PeerTube-f7ce623db1225b7b6f8383c33cab9515b36907fe.zip
Don't log error on static 404
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/static.ts29
1 files changed, 25 insertions, 4 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 7668ceb82..0b5c12b76 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -1,3 +1,4 @@
1import { HttpStatusCode } from '@shared/models'
1import cors from 'cors' 2import cors from 'cors'
2import express from 'express' 3import express from 'express'
3import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
@@ -11,24 +12,28 @@ staticRouter.use(cors())
11// Videos path for webseed 12// Videos path for webseed
12staticRouter.use( 13staticRouter.use(
13 STATIC_PATHS.WEBSEED, 14 STATIC_PATHS.WEBSEED,
14 express.static(CONFIG.STORAGE.VIDEOS_DIR, { fallthrough: false }) // 404 because we don't have this video 15 express.static(CONFIG.STORAGE.VIDEOS_DIR, { fallthrough: false }),
16 handleStaticError
15) 17)
16staticRouter.use( 18staticRouter.use(
17 STATIC_PATHS.REDUNDANCY, 19 STATIC_PATHS.REDUNDANCY,
18 express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }) // 404 because we don't have this video 20 express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }),
21 handleStaticError
19) 22)
20 23
21// HLS 24// HLS
22staticRouter.use( 25staticRouter.use(
23 STATIC_PATHS.STREAMING_PLAYLISTS.HLS, 26 STATIC_PATHS.STREAMING_PLAYLISTS.HLS,
24 express.static(HLS_STREAMING_PLAYLIST_DIRECTORY, { fallthrough: false }) // 404 if the file does not exist 27 express.static(HLS_STREAMING_PLAYLIST_DIRECTORY, { fallthrough: false }),
28 handleStaticError
25) 29)
26 30
27// Thumbnails path for express 31// Thumbnails path for express
28const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR 32const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR
29staticRouter.use( 33staticRouter.use(
30 STATIC_PATHS.THUMBNAILS, 34 STATIC_PATHS.THUMBNAILS,
31 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist 35 express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }),
36 handleStaticError
32) 37)
33 38
34// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
@@ -36,3 +41,19 @@ staticRouter.use(
36export { 41export {
37 staticRouter 42 staticRouter
38} 43}
44
45// ---------------------------------------------------------------------------
46
47function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
48 const message = err.message || ''
49
50 if (message.includes('ENOENT')) {
51 return res.fail({
52 status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
53 message: err.message,
54 type: err.name
55 })
56 }
57
58 return next(err)
59}