diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-13 11:21:19 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-13 11:21:19 +0200 |
commit | f7ce623db1225b7b6f8383c33cab9515b36907fe (patch) | |
tree | 6d940af0c1a6aa8279fcb1eb793c001c512b5755 /server/controllers/static.ts | |
parent | ea8107bff8e544594716a76d30ff372fc80d755c (diff) | |
download | PeerTube-f7ce623db1225b7b6f8383c33cab9515b36907fe.tar.gz PeerTube-f7ce623db1225b7b6f8383c33cab9515b36907fe.tar.zst PeerTube-f7ce623db1225b7b6f8383c33cab9515b36907fe.zip |
Don't log error on static 404
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r-- | server/controllers/static.ts | 29 |
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 @@ | |||
1 | import { HttpStatusCode } from '@shared/models' | ||
1 | import cors from 'cors' | 2 | import cors from 'cors' |
2 | import express from 'express' | 3 | import express from 'express' |
3 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
@@ -11,24 +12,28 @@ staticRouter.use(cors()) | |||
11 | // Videos path for webseed | 12 | // Videos path for webseed |
12 | staticRouter.use( | 13 | staticRouter.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 | ) |
16 | staticRouter.use( | 18 | staticRouter.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 |
22 | staticRouter.use( | 25 | staticRouter.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 |
28 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR | 32 | const thumbnailsPhysicalPath = CONFIG.STORAGE.THUMBNAILS_DIR |
29 | staticRouter.use( | 33 | staticRouter.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( | |||
36 | export { | 41 | export { |
37 | staticRouter | 42 | staticRouter |
38 | } | 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 | } | ||