From 44c113f829e148129ae8b143c78338c5dd3818e1 Mon Sep 17 00:00:00 2001 From: Dima Lazerka <58356625+dima-vm@users.noreply.github.com> Date: Thu, 14 Dec 2023 21:19:54 -0800 Subject: [PATCH] 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 --------- Co-authored-by: Yury Moladau (cherry picked from commit cd277e3f848e418087cab07b49b74e119935b5af) --- app/vmui/packages/vmui/src/hooks/useFetchQuery.ts | 6 +++++- app/vmui/packages/vmui/src/types/index.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts b/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts index a9e3cc74c..980527713 100644 --- a/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts +++ b/app/vmui/packages/vmui/src/hooks/useFetchQuery.ts @@ -136,7 +136,11 @@ export const useFetchQuery = ({ totalLength += resp.data.result.length; } else { 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++; } diff --git a/app/vmui/packages/vmui/src/types/index.ts b/app/vmui/packages/vmui/src/types/index.ts index c04aea5bd..f4bd75873 100644 --- a/app/vmui/packages/vmui/src/types/index.ts +++ b/app/vmui/packages/vmui/src/types/index.ts @@ -47,7 +47,8 @@ export enum ErrorTypes { traceNotFound = "Not found the tracing information", emptyTitle = "Please enter title", 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 {