mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: show ban reason and expiry in write api responses, if user is banned
This commit is contained in:
@@ -357,9 +357,26 @@ helpers.formatApiResponse = async (statusCode, res, payload) => {
|
|||||||
});
|
});
|
||||||
} else if (payload instanceof Error) {
|
} else if (payload instanceof Error) {
|
||||||
const message = payload.message;
|
const message = payload.message;
|
||||||
|
const response = {};
|
||||||
|
|
||||||
// Update status code based on some common error codes
|
// Update status code based on some common error codes
|
||||||
switch (payload.message) {
|
switch (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]]':
|
case '[[error:no-privileges]]':
|
||||||
statusCode = 403;
|
statusCode = 403;
|
||||||
break;
|
break;
|
||||||
@@ -370,6 +387,7 @@ helpers.formatApiResponse = async (statusCode, res, payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const returnPayload = helpers.generateError(statusCode, message);
|
const returnPayload = helpers.generateError(statusCode, message);
|
||||||
|
returnPayload.response = response;
|
||||||
|
|
||||||
if (global.env === 'development') {
|
if (global.env === 'development') {
|
||||||
returnPayload.stack = payload.stack;
|
returnPayload.stack = payload.stack;
|
||||||
|
|||||||
Reference in New Issue
Block a user