VMUI: Handle unknown query error response type (#5451)

* VMUI: Handle unknown query error response type

* vmui: add error text for unknown error type

* Simplify nested `if`s for unknown error

Accepting @Loori-R's suggestion

Co-authored-by: Yury Molodov <yurymolodov@gmail.com>

---------

Co-authored-by: Yury Moladau <yurymolodov@gmail.com>
This commit is contained in:
Dima Lazerka 2023-12-14 21:19:54 -08:00 committed by GitHub
parent 0a6a2e455d
commit cd277e3f84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -136,7 +136,11 @@ export const useFetchQuery = ({
totalLength += resp.data.result.length; totalLength += resp.data.result.length;
} else { } else {
tempData.push({ metric: {}, values: [], group: counter } as MetricBase); tempData.push({ metric: {}, values: [], group: counter } as MetricBase);
setQueryErrors(prev => [...prev, `${resp.errorType}\r\n${resp?.error}`]); const errorType = resp.errorType || ErrorTypes.unknownType;
const errorMessage = resp?.error || resp?.message || "see console for more details";
const error = [errorType, errorMessage].join(",\r\n");
setQueryErrors(prev => [...prev, `${error}`]);
console.error(`Fetch query error: ${errorType}`, resp);
} }
counter++; counter++;
} }

View file

@ -47,7 +47,8 @@ export enum ErrorTypes {
traceNotFound = "Not found the tracing information", traceNotFound = "Not found the tracing information",
emptyTitle = "Please enter title", emptyTitle = "Please enter title",
positiveNumber = "Please enter positive number", positiveNumber = "Please enter positive number",
validStep = "Please enter a valid step" validStep = "Please enter a valid step",
unknownType = "Unknown server response format: must have 'errorType'",
} }
export interface PanelSettings { export interface PanelSettings {