From eec63bbc0f4fdb39e56f37127b35c449f90a135f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 28 Dec 2017 14:29:57 +0100 Subject: Improve check follow params tests --- server/middlewares/oauth.ts | 6 +++++- server/middlewares/user-right.ts | 10 ++++++++-- server/middlewares/validators/follows.ts | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index e59168ea8..12872c4a5 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -17,7 +17,11 @@ function authenticate (req: express.Request, res: express.Response, next: expres return res.sendStatus(500) } - if (res.statusCode === 401 || res.statusCode === 400 || res.statusCode === 503) return res.end() + if (res.statusCode === 401 || res.statusCode === 400 || res.statusCode === 503) { + return res.json({ + error: 'Authentication failed.' + }).end() + } return next() }) diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts index 5bb5bdfbd..7cea7aa1e 100644 --- a/server/middlewares/user-right.ts +++ b/server/middlewares/user-right.ts @@ -8,8 +8,14 @@ function ensureUserHasRight (userRight: UserRight) { return function (req: express.Request, res: express.Response, next: express.NextFunction) { const user = res.locals.oauth.token.user as UserModel if (user.hasRight(userRight) === false) { - logger.info('User %s does not have right %s to access to %s.', user.username, UserRight[userRight], req.path) - return res.sendStatus(403) + const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.` + logger.info(message) + + return res.status(403) + .json({ + error: message + }) + .end() } return next() diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 7dadf6a19..991a2e175 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -41,7 +41,11 @@ const removeFollowingValidator = [ const follow = await ActorFollowModel.loadByActorAndTargetHost(serverActor.id, req.params.host) if (!follow) { - return res.status(404) + return res + .status(404) + .json({ + error: `Follower ${req.params.host} not found.` + }) .end() } -- cgit v1.2.3