]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/error.ts
Move test functions outside extra-utils
[github/Chocobozzz/PeerTube.git] / server / middlewares / error.ts
index af5a9c29a00e58ff887d879837d4959374ebf4df..34c87a26d8dc7522670c02b357c0d3a095d3c8de 100644 (file)
@@ -1,5 +1,6 @@
-import * as express from 'express'
+import express from 'express'
 import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details'
+import { logger } from '@server/helpers/logger'
 import { HttpStatusCode } from '@shared/models'
 
 function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -18,7 +19,8 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
 
     res.status(status)
     res.setHeader('Content-Type', 'application/problem+json')
-    res.json(new ProblemDocument({
+
+    const json = new ProblemDocument({
       status,
       title,
       instance,
@@ -28,7 +30,11 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
       type: type
         ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}`
         : undefined
-    }, extension))
+    }, extension)
+
+    logger.debug('Bad HTTP request.', { json })
+
+    res.json(json)
   }
 
   if (next) next()