]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/middlewares/accounts.ts
refactor API errors to standard error format
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / accounts.ts
index 5addd3e1a24d8ebf7d62db71721fa50d7349f710..7db79bc488f9407c5f2381a5aa4694f859fb9085 100644 (file)
@@ -27,15 +27,15 @@ async function doesAccountExist (p: Promise<MAccountDefault>, res: Response, sen
 
   if (!account) {
     if (sendNotFound === true) {
-      res.status(HttpStatusCode.NOT_FOUND_404)
-         .json({ error: 'Account not found' })
+      res.fail({
+        status: HttpStatusCode.NOT_FOUND_404,
+        message: 'Account not found'
+      })
     }
-
     return false
   }
 
   res.locals.account = account
-
   return true
 }
 
@@ -43,14 +43,14 @@ async function doesUserFeedTokenCorrespond (id: number, token: string, res: Resp
   const user = await UserModel.loadByIdWithChannels(parseInt(id + '', 10))
 
   if (token !== user.feedToken) {
-    res.status(HttpStatusCode.FORBIDDEN_403)
-       .json({ error: 'User and token mismatch' })
-
+    res.fail({
+      status: HttpStatusCode.FORBIDDEN_403,
+      message: 'User and token mismatch'
+    })
     return false
   }
 
   res.locals.user = user
-
   return true
 }