From 395aea292e25aa726be04faa7bce726ceb7ac53c Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 31 Dec 2021 23:59:14 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=87=20Updates=20widget=20request=20to?= =?UTF-8?q?=20only=20apply=20headers=20when=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎇 Happy New Year 🎇 --- src/mixins/WidgetMixin.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mixins/WidgetMixin.js b/src/mixins/WidgetMixin.js index ef35644c..833c8b38 100644 --- a/src/mixins/WidgetMixin.js +++ b/src/mixins/WidgetMixin.js @@ -16,6 +16,7 @@ const WidgetMixin = { }, data: () => ({ progress: new ProgressBar({ color: 'var(--progress-bar)' }), + overrideProxyChoice: false, }), /* When component mounted, fetch initial data */ mounted() { @@ -27,7 +28,7 @@ const WidgetMixin = { return `${baseUrl}${serviceEndpoints.corsProxy}`; }, useProxy() { - return this.options.useProxy; + return this.options.useProxy || this.overrideProxyChoice; }, }, methods: { @@ -60,15 +61,20 @@ const WidgetMixin = { return { content, trigger: 'hover focus', delay: 250 }; }, /* Makes data request, returns promise */ - makeRequest(endpoint, options = {}) { + makeRequest(endpoint, options) { // Request Options const method = 'GET'; const url = this.useProxy ? this.proxyReqEndpoint : endpoint; - const headers = this.useProxy ? { 'Target-URL': endpoint, ...options } : options; + const CustomHeaders = options ? { ...JSON.stringify(options) } : null; + const headers = this.useProxy + ? { 'Target-URL': endpoint, CustomHeaders } : CustomHeaders; // Make request return new Promise((resolve, reject) => { axios.request({ method, url, headers }) .then((response) => { + if (response.data.success === false) { + this.error('Proxy returned error from target server', response.data.message); + } resolve(response.data); }) .catch((dataFetchError) => {