diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000..aafe5342cc Binary files /dev/null and b/dump.rdb differ diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index c17e701b79..581e537ff8 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -20,6 +20,31 @@ const helpers = module.exports; const relative_path = nconf.get('relative_path'); const url = nconf.get('url'); +const handleSuccessfulResponse = (statusCode, res, payload) => { + if (res.req.loggedIn) { + res.set('cache-control', 'private'); + } + + let code = 'ok'; + let message = 'OK'; + switch (statusCode) { + case 202: + code = 'accepted'; + message = 'Accepted'; + break; + + case 204: + code = 'no-content'; + message = 'No Content'; + break; + } + + res.status(statusCode).json({ + status: { code, message }, + response: payload || {}, + }); +}; + helpers.noScriptErrors = async function (req, res, error, httpStatus) { if (req.body.noscript !== 'true') { if (typeof error === 'string') { @@ -454,28 +479,7 @@ helpers.formatApiResponse = async (statusCode, res, payload) => { } if (String(statusCode).startsWith('2')) { - if (res.req.loggedIn) { - res.set('cache-control', 'private'); - } - - let code = 'ok'; - let message = 'OK'; - switch (statusCode) { - case 202: - code = 'accepted'; - message = 'Accepted'; - break; - - case 204: - code = 'no-content'; - message = 'No Content'; - break; - } - - res.status(statusCode).json({ - status: { code, message }, - response: payload || {}, - }); + handleSuccessfulResponse(statusCode, res, payload); } else if (payload instanceof Error || typeof payload === 'string') { const message = payload instanceof Error ? payload.message : payload; const response = {};