]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Prevent logging an error on lazy static 404
authorChocobozzz <me@florianbigard.com>
Wed, 27 Jul 2022 12:38:07 +0000 (14:38 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 27 Jul 2022 12:38:07 +0000 (14:38 +0200)
server/controllers/lazy-static.ts
server/controllers/static.ts
server/middlewares/error.ts

index 0cab5dcd082f63a4cee7ddb7c279067b9861e47e..b082e41f64ebaadeab9c87854f7061cd5c66e32f 100644 (file)
@@ -7,7 +7,7 @@ import { logger } from '../helpers/logger'
 import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants'
 import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
 import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor'
-import { asyncMiddleware } from '../middlewares'
+import { asyncMiddleware, handleStaticError } from '../middlewares'
 import { ActorImageModel } from '../models/actor/actor-image'
 
 const lazyStaticRouter = express.Router()
@@ -16,27 +16,32 @@ lazyStaticRouter.use(cors())
 
 lazyStaticRouter.use(
   LAZY_STATIC_PATHS.AVATARS + ':filename',
-  asyncMiddleware(getActorImage)
+  asyncMiddleware(getActorImage),
+  handleStaticError
 )
 
 lazyStaticRouter.use(
   LAZY_STATIC_PATHS.BANNERS + ':filename',
-  asyncMiddleware(getActorImage)
+  asyncMiddleware(getActorImage),
+  handleStaticError
 )
 
 lazyStaticRouter.use(
   LAZY_STATIC_PATHS.PREVIEWS + ':filename',
-  asyncMiddleware(getPreview)
+  asyncMiddleware(getPreview),
+  handleStaticError
 )
 
 lazyStaticRouter.use(
   LAZY_STATIC_PATHS.VIDEO_CAPTIONS + ':filename',
-  asyncMiddleware(getVideoCaption)
+  asyncMiddleware(getVideoCaption),
+  handleStaticError
 )
 
 lazyStaticRouter.use(
   LAZY_STATIC_PATHS.TORRENTS + ':filename',
-  asyncMiddleware(getTorrent)
+  asyncMiddleware(getTorrent),
+  handleStaticError
 )
 
 // ---------------------------------------------------------------------------
index 0b5c12b7603cf540afa19d04de7509befbf40431..33c429eb17a235a1fed1adb52aa326bcbc3b992a 100644 (file)
@@ -1,6 +1,6 @@
-import { HttpStatusCode } from '@shared/models'
 import cors from 'cors'
 import express from 'express'
+import { handleStaticError } from '@server/middlewares'
 import { CONFIG } from '../initializers/config'
 import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants'
 
@@ -41,19 +41,3 @@ staticRouter.use(
 export {
   staticRouter
 }
-
-// ---------------------------------------------------------------------------
-
-function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
-  const message = err.message || ''
-
-  if (message.includes('ENOENT')) {
-    return res.fail({
-      status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
-      message: err.message,
-      type: err.name
-    })
-  }
-
-  return next(err)
-}
index 34c87a26d8dc7522670c02b357c0d3a095d3c8de..96a85012ac495353b87453913de3ffdaa64b83e3 100644 (file)
@@ -40,6 +40,21 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
   if (next) next()
 }
 
+function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
+  const message = err.message || ''
+
+  if (message.includes('ENOENT')) {
+    return res.fail({
+      status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500,
+      message: err.message,
+      type: err.name
+    })
+  }
+
+  return next(err)
+}
+
 export {
-  apiFailMiddleware
+  apiFailMiddleware,
+  handleStaticError
 }