Display parsing errors in InfluxQLEditor if present

pull/4392/head
Christopher Henn 2018-09-06 11:00:13 -07:00 committed by Chris Henn
parent f063245db8
commit ca0d885bf5
2 changed files with 27 additions and 7 deletions

View File

@ -148,16 +148,25 @@ const handleSuccess = (
}
const handleError = (
error,
error: string,
query: Query,
editQueryStatus: EditQueryStatusFunction
): void => {
const message =
getDeep<string>(error, 'data.message', '') ||
getDeep<string>(error, 'message', 'Could not retrieve data')
// 400 from chrono server = fail
editQueryStatus(query.id, {
error: message,
error: extractErrorMessage(error),
})
}
const extractErrorMessage = (errorMessage: string): string => {
if (!errorMessage) {
return 'Could not retrieve data'
}
const parseErrorMatch = errorMessage.match('error parsing query')
if (parseErrorMatch) {
return errorMessage.slice(parseErrorMatch.index)
}
return errorMessage
}

View File

@ -7,8 +7,19 @@ const proxy = async msg => {
method: 'POST',
body: JSON.stringify({query, rp, db, uuid}),
})
const data = await response.json()
if (!response.ok) {
let message = 'proxy request failed'
if (data && data.message) {
message = data.message
}
return Promise.reject(message)
}
return {data}
}