Node.js based forum software built for the modern web
feat: show ban reason and expiry in write api responses, if user is banned
Julian Lamafb26bfe48bd
diff --git a/src/controllers/helpers.js b/src/controllers/helpers.jsindex e5377b4b42..86aee6ea47 100644--- a/src/controllers/helpers.js+++ b/src/controllers/helpers.js@@ -357,9 +357,26 @@ helpers.formatApiResponse = async (statusCode, res, payload) => {});} else if (payload instanceof Error) {const message = payload.message;+ const response = {};// Update status code based on some common error codesswitch (payload.message) {+ case '[[error:user-banned]]': {+ const [reason, expiry] = await Promise.all([+ user.bans.getReason(res.req.uid),+ user.getUserField(res.req.uid, 'banned:expire'),+ ]);++ response.reason = reason;+ if (expiry) {+ Object.assign(response, {+ expiry,+ expiryISO: new Date(expiry).toISOString(),+ expiryLocaleString: new Date(expiry).toLocaleString(),+ });+ }+ } // intentional fall through+case '[[error:no-privileges]]':statusCode = 403;break;@@ -370,6 +387,7 @@ helpers.formatApiResponse = async (statusCode, res, payload) => {}const returnPayload = helpers.generateError(statusCode, message);+ returnPayload.response = response;if (global.env === 'development') {returnPayload.stack = payload.stack;