From 82fef9301fec200a84e9d0053d084e72c71ae655 Mon Sep 17 00:00:00 2001 From: Jon Wiese Date: Tue, 1 Oct 2024 08:50:14 -0600 Subject: [PATCH] Reload page when we get a 401 back from bcapp --- src/lib/request.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/request.js b/src/lib/request.js index 8e02f16..5c71cc9 100644 --- a/src/lib/request.js +++ b/src/lib/request.js @@ -88,12 +88,18 @@ export default function (relativeUrl, opts, callback) { return fetch(url, config) .then((response) => { - if (response.headers.get('content-type').indexOf('application/json') !== -1) { - return response.json(); + let result = null; + + if (response.status === 401 && response.headers.get('X-BC-Preview-Mode').indexOf('true') !== -1) { + window.location.reload(); + } else if (response.headers.get('content-type').indexOf('application/json') !== -1) { + result = response.json(); + } else { + result = response.text(); } - return response.text(); - }) - .then((response) => { + + return result; + }).then((response) => { const content = options.remote ? response.content : response; let ret = response;