From 28084bd8d67610b3bc9bb6ab160fee85a3117603 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 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/request.js b/src/lib/request.js index 8e02f16..ba11899 100644 --- a/src/lib/request.js +++ b/src/lib/request.js @@ -88,12 +88,19 @@ 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(); + } + result = response.text(); } - return response.text(); - }) - .then((response) => { + + return result; + }).then((response) => { const content = options.remote ? response.content : response; let ret = response;