aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-27 14:38:07 +0200
committerChocobozzz <me@florianbigard.com>2022-07-27 14:38:07 +0200
commiteb7b48ce84e5872d1333edd892f2e6104a18d7f1 (patch)
treefed58d9ef381fb1be4936bc636d0392feaec820c /server
parente3d6c6434f570f77c0532f86c82f78bcafb399ec (diff)
downloadPeerTube-eb7b48ce84e5872d1333edd892f2e6104a18d7f1.tar.gz
PeerTube-eb7b48ce84e5872d1333edd892f2e6104a18d7f1.tar.zst
PeerTube-eb7b48ce84e5872d1333edd892f2e6104a18d7f1.zip
Prevent logging an error on lazy static 404
Diffstat (limited to 'server')
-rw-r--r--server/controllers/lazy-static.ts17
-rw-r--r--server/controllers/static.ts18
-rw-r--r--server/middlewares/error.ts17
3 files changed, 28 insertions, 24 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts
index 0cab5dcd0..b082e41f6 100644
--- a/server/controllers/lazy-static.ts
+++ b/server/controllers/lazy-static.ts
@@ -7,7 +7,7 @@ import { logger } from '../helpers/logger'
7import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' 7import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants'
8import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' 8import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
9import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor' 9import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor'
10import { asyncMiddleware } from '../middlewares' 10import { asyncMiddleware, handleStaticError } from '../middlewares'
11import { ActorImageModel } from '../models/actor/actor-image' 11import { ActorImageModel } from '../models/actor/actor-image'
12 12
13const lazyStaticRouter = express.Router() 13const lazyStaticRouter = express.Router()
@@ -16,27 +16,32 @@ lazyStaticRouter.use(cors())
16 16
17lazyStaticRouter.use( 17lazyStaticRouter.use(
18 LAZY_STATIC_PATHS.AVATARS + ':filename', 18 LAZY_STATIC_PATHS.AVATARS + ':filename',
19 asyncMiddleware(getActorImage) 19 asyncMiddleware(getActorImage),
20 handleStaticError
20) 21)
21 22
22lazyStaticRouter.use( 23lazyStaticRouter.use(
23 LAZY_STATIC_PATHS.BANNERS + ':filename', 24 LAZY_STATIC_PATHS.BANNERS + ':filename',
24 asyncMiddleware(getActorImage) 25 asyncMiddleware(getActorImage),
26 handleStaticError
25) 27)
26 28
27lazyStaticRouter.use( 29lazyStaticRouter.use(
28 LAZY_STATIC_PATHS.PREVIEWS + ':filename', 30 LAZY_STATIC_PATHS.PREVIEWS + ':filename',
29 asyncMiddleware(getPreview) 31 asyncMiddleware(getPreview),
32 handleStaticError
30) 33)
31 34
32lazyStaticRouter.use( 35lazyStaticRouter.use(
33 LAZY_STATIC_PATHS.VIDEO_CAPTIONS + ':filename', 36 LAZY_STATIC_PATHS.VIDEO_CAPTIONS + ':filename',
34 asyncMiddleware(getVideoCaption) 37 asyncMiddleware(getVideoCaption),
38 handleStaticError
35) 39)
36 40
37lazyStaticRouter.use( 41lazyStaticRouter.use(
38 LAZY_STATIC_PATHS.TORRENTS + ':filename', 42 LAZY_STATIC_PATHS.TORRENTS + ':filename',
39 asyncMiddleware(getTorrent) 43 asyncMiddleware(getTorrent),
44 handleStaticError
40) 45)
41 46
42// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 0b5c12b76..33c429eb1 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -1,6 +1,6 @@
1import { HttpStatusCode } from '@shared/models'
2import cors from 'cors' 1import cors from 'cors'
3import express from 'express' 2import express from 'express'
3import { handleStaticError } from '@server/middlewares'
4import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
5import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' 5import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
6 6
@@ -41,19 +41,3 @@ staticRouter.use(
41export { 41export {
42 staticRouter 42 staticRouter
43} 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}
diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts
index 34c87a26d..96a85012a 100644
--- a/server/middlewares/error.ts
+++ b/server/middlewares/error.ts
@@ -40,6 +40,21 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
40 if (next) next() 40 if (next) next()
41} 41}
42 42
43function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
44 const message = err.message || ''
45
46 if (message.includes('ENOENT')) {
47 return res.fail({
48 status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
49 message: err.message,
50 type: err.name
51 })
52 }
53
54 return next(err)
55}
56
43export { 57export {
44 apiFailMiddleware 58 apiFailMiddleware,
59 handleStaticError
45} 60}