From c1cf7f35aefe00a88ce3219e6688b92192480c7c Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Mon, 28 Feb 2022 22:23:51 +0100 Subject: [PATCH 1/5] fix(ui): propagate influxql error message --- ui/src/worker/jobs/proxy.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/src/worker/jobs/proxy.ts b/ui/src/worker/jobs/proxy.ts index 4023ed2a03..827ad1499c 100644 --- a/ui/src/worker/jobs/proxy.ts +++ b/ui/src/worker/jobs/proxy.ts @@ -32,7 +32,19 @@ const proxy = async (msg: ProxyMsg): Promise<{data: any}> => { 'response:', data ) - Promise.reject(response.statusText || `error ${response.status}`) + let errorMessage = response.statusText || `error ${response.status}` + // try to parse error message from JSON payload + if (response.headers.get('content-type').includes('application/json')) { + try { + const {message} = JSON.parse(data) + if (message) { + errorMessage = message + } + } catch (e) { + // ignore silently, unrecognized error message + } + } + return Promise.reject(errorMessage) } catch (e) { console.error('failed to POST url:', url, 'body:', body, 'error:', e) return Promise.reject(e.message ? e.message : String(e)) From 6defd734c9e3cf730d5d624cbdc8ee69ccdbc35c Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Mon, 28 Feb 2022 22:25:09 +0100 Subject: [PATCH 2/5] fix(ui): make influxQL query status robust --- ui/src/shared/components/QueryStatus.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/src/shared/components/QueryStatus.tsx b/ui/src/shared/components/QueryStatus.tsx index 741582a40c..33ee15f3b1 100644 --- a/ui/src/shared/components/QueryStatus.tsx +++ b/ui/src/shared/components/QueryStatus.tsx @@ -36,19 +36,19 @@ class QueryStatus extends PureComponent {
- {status.error || status.warn || status.success} + {String(status.error || status.warn || status.success)} {children}
From 9f6db6dd240a353927e7ab358bd4202149750887 Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Mon, 28 Feb 2022 22:33:27 +0100 Subject: [PATCH 3/5] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b20c48b4..8e1c251ab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Bug Fixes 1. [#5862](https://github.com/influxdata/chronograf/pull/5862): Respect BASE_PATH when serving API docs. +1. [#5874](https://github.com/influxdata/chronograf/pull/5874): Propagate InfluxQL errors to UI. ### Other From ec88602b264869ffe181129a18ef5412e4842730 Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Mon, 28 Feb 2022 22:41:41 +0100 Subject: [PATCH 4/5] fix(ui): fix rejection of HTTP GET calls --- ui/src/utils/ajax.ts | 4 +++- ui/src/worker/jobs/get.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ui/src/utils/ajax.ts b/ui/src/utils/ajax.ts index c7c7f31ec6..49d0a8631b 100644 --- a/ui/src/utils/ajax.ts +++ b/ui/src/utils/ajax.ts @@ -183,7 +183,9 @@ export async function getAJAX(url: string): Promise<{data: T}> { 'response:', data ) - Promise.reject(new Error(response.statusText || `error ${response.status}`)) + return Promise.reject( + new Error(response.statusText || `error ${response.status}`) + ) } catch (e) { console.error('failed to GET url:', url, 'error:', e) return Promise.reject(e) diff --git a/ui/src/worker/jobs/get.ts b/ui/src/worker/jobs/get.ts index adbf388fcc..eceac44a8d 100644 --- a/ui/src/worker/jobs/get.ts +++ b/ui/src/worker/jobs/get.ts @@ -20,7 +20,9 @@ const get = async (msg: Message): Promise => { 'response:', data ) - Promise.reject(new Error(response.statusText || `error ${response.status}`)) + return Promise.reject( + new Error(response.statusText || `error ${response.status}`) + ) } catch (e) { console.error('failed to GET url:', url, 'error:', e) return Promise.reject(e) From 4b5a3e807a95084aeebe100d4f511f37b218eac6 Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Mon, 28 Feb 2022 22:45:29 +0100 Subject: [PATCH 5/5] fix(ui): prefer error message from HTTP response --- ui/src/utils/ajax.ts | 16 +++++++++++++--- ui/src/worker/jobs/get.ts | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ui/src/utils/ajax.ts b/ui/src/utils/ajax.ts index 49d0a8631b..78b6a7e8a2 100644 --- a/ui/src/utils/ajax.ts +++ b/ui/src/utils/ajax.ts @@ -183,9 +183,19 @@ export async function getAJAX(url: string): Promise<{data: T}> { 'response:', data ) - return Promise.reject( - new Error(response.statusText || `error ${response.status}`) - ) + let errorMessage = response.statusText || `error ${response.status}` + // try to parse error message from JSON payload + if (response.headers.get('content-type').includes('application/json')) { + try { + const {message} = JSON.parse(data) + if (message) { + errorMessage = message + } + } catch (e) { + // ignore silently, unrecognized error message + } + } + return Promise.reject(new Error(errorMessage)) } catch (e) { console.error('failed to GET url:', url, 'error:', e) return Promise.reject(e) diff --git a/ui/src/worker/jobs/get.ts b/ui/src/worker/jobs/get.ts index eceac44a8d..dd11133832 100644 --- a/ui/src/worker/jobs/get.ts +++ b/ui/src/worker/jobs/get.ts @@ -20,9 +20,19 @@ const get = async (msg: Message): Promise => { 'response:', data ) - return Promise.reject( - new Error(response.statusText || `error ${response.status}`) - ) + let errorMessage = response.statusText || `error ${response.status}` + // try to parse error message from JSON payload + if (response.headers.get('content-type').includes('application/json')) { + try { + const {message} = JSON.parse(data) + if (message) { + errorMessage = message + } + } catch (e) { + // ignore silently, unrecognized error message + } + } + return Promise.reject(new Error(errorMessage)) } catch (e) { console.error('failed to GET url:', url, 'error:', e) return Promise.reject(e)