From 6cb844071517eac2ddd96b13949de3e4c2f6910a Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Fri, 30 Jun 2017 23:38:31 -0600 Subject: [PATCH] Fix #5793 Use a custom header instead --- public/src/ajaxify.js | 12 +++++++++++- src/controllers/errors.js | 2 +- src/controllers/helpers.js | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 26c9950254..9ca9052dc9 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -293,11 +293,21 @@ $(document).ready(function () { headers: { 'X-Return-To': app.previousUrl, }, - success: function (data) { + success: function (data, textStatus, xhr) { if (!data) { return; } + if (xhr.getResponseHeader('X-Redirect')) { + return callback({ + data: { + status: 302, + responseJSON: data, + }, + textStatus: 'error', + }); + } + ajaxify.data = data; data.config = config; diff --git a/src/controllers/errors.js b/src/controllers/errors.js index 99614f9e87..177bcaa769 100644 --- a/src/controllers/errors.js +++ b/src/controllers/errors.js @@ -45,7 +45,7 @@ exports.handleErrors = function (err, req, res, next) { // eslint-disable-line n var status = parseInt(err.status, 10); if ((status === 302 || status === 308) && err.path) { - return res.locals.isAPI ? res.status(status).json(err.path) : res.redirect(err.path); + return res.locals.isAPI ? res.set('X-Redirect', err.path).status(200).json(err.path) : res.redirect(err.path); } winston.error(req.path + '\n', err.stack); diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 761faafa82..8db1d6266f 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -53,7 +53,7 @@ helpers.notAllowed = function (req, res, error) { helpers.redirect = function (res, url) { if (res.locals.isAPI) { - res.status(308).json(url); + res.set('X-Redirect', url).status(200).json(url); } else { res.redirect(nconf.get('relative_path') + encodeURI(url)); }