diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-27 14:38:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-27 14:38:07 +0200 |
commit | eb7b48ce84e5872d1333edd892f2e6104a18d7f1 (patch) | |
tree | fed58d9ef381fb1be4936bc636d0392feaec820c /server | |
parent | e3d6c6434f570f77c0532f86c82f78bcafb399ec (diff) | |
download | PeerTube-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.ts | 17 | ||||
-rw-r--r-- | server/controllers/static.ts | 18 | ||||
-rw-r--r-- | server/middlewares/error.ts | 17 |
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' | |||
7 | import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' | 7 | import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' |
8 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | 8 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' |
9 | import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor' | 9 | import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor' |
10 | import { asyncMiddleware } from '../middlewares' | 10 | import { asyncMiddleware, handleStaticError } from '../middlewares' |
11 | import { ActorImageModel } from '../models/actor/actor-image' | 11 | import { ActorImageModel } from '../models/actor/actor-image' |
12 | 12 | ||
13 | const lazyStaticRouter = express.Router() | 13 | const lazyStaticRouter = express.Router() |
@@ -16,27 +16,32 @@ lazyStaticRouter.use(cors()) | |||
16 | 16 | ||
17 | lazyStaticRouter.use( | 17 | lazyStaticRouter.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 | ||
22 | lazyStaticRouter.use( | 23 | lazyStaticRouter.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 | ||
27 | lazyStaticRouter.use( | 29 | lazyStaticRouter.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 | ||
32 | lazyStaticRouter.use( | 35 | lazyStaticRouter.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 | ||
37 | lazyStaticRouter.use( | 41 | lazyStaticRouter.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 @@ | |||
1 | import { HttpStatusCode } from '@shared/models' | ||
2 | import cors from 'cors' | 1 | import cors from 'cors' |
3 | import express from 'express' | 2 | import express from 'express' |
3 | import { handleStaticError } from '@server/middlewares' | ||
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' | 5 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' |
6 | 6 | ||
@@ -41,19 +41,3 @@ staticRouter.use( | |||
41 | export { | 41 | export { |
42 | staticRouter | 42 | staticRouter |
43 | } | 43 | } |
44 | |||
45 | // --------------------------------------------------------------------------- | ||
46 | |||
47 | function 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 | ||
43 | function 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 | |||
43 | export { | 57 | export { |
44 | apiFailMiddleware | 58 | apiFailMiddleware, |
59 | handleStaticError | ||
45 | } | 60 | } |