Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): propagate all InfluxQL error messages to UI #5874

Merged
merged 5 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions ui/src/shared/components/QueryStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ class QueryStatus extends PureComponent<Props> {
<div className="query-editor--status">
<span
className={classnames('query-status-output', {
'query-status-output--error': status.error,
'query-status-output--success': status.success,
'query-status-output--warning': status.warn,
'query-status-output--error': !!status.error,
'query-status-output--success': !!status.success,
'query-status-output--warning': !!status.warn,
})}
>
<span
className={classnames('icon', {
stop: status.error,
checkmark: status.success,
'alert-triangle': status.warn,
stop: !!status.error,
checkmark: !!status.success,
'alert-triangle': !!status.warn,
})}
/>
{status.error || status.warn || status.success}
{String(status.error || status.warn || status.success)}
</span>
{children}
</div>
Expand Down
14 changes: 13 additions & 1 deletion ui/src/utils/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,19 @@ export async function getAJAX<T = any>(url: string): Promise<{data: T}> {
'response:',
data
)
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)
Expand Down
14 changes: 13 additions & 1 deletion ui/src/worker/jobs/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ const get = async (msg: Message): Promise<any> => {
'response:',
data
)
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)
Expand Down
14 changes: 13 additions & 1 deletion ui/src/worker/jobs/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down