From 40c9fca91831f7241bca423848474b808e2ce1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 20 Sep 2021 10:11:25 -0400 Subject: [PATCH] fix: #9811, send bodyClass on 403 use helpers.formatApiResponse for /api/v3 routes only --- src/controllers/helpers.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 9e54c27e71..e525fb80cc 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -12,6 +12,7 @@ const privileges = require('../privileges'); const categories = require('../categories'); const plugins = require('../plugins'); const meta = require('../meta'); +const middlewareHelpers = require('../middleware/helpers'); const helpers = module.exports; @@ -121,7 +122,17 @@ helpers.notAllowed = async function (req, res, error) { if (req.loggedIn || req.uid === -1) { if (res.locals.isAPI) { - helpers.formatApiResponse(403, res, error); + if (req.path.startsWith('/api/v3')) { + helpers.formatApiResponse(403, res, error); + } else { + res.status(403).json({ + path: req.path.replace(/^\/api/, ''), + loggedIn: req.loggedIn, + error: error, + title: '[[global:403.title]]', + bodyClass: middlewareHelpers.buildBodyClass(req, res), + }); + } } else { const middleware = require('../middleware'); await middleware.buildHeaderAsync(req, res);