From 186504d025b486438e456b19be2e5bb416b469ec Mon Sep 17 00:00:00 2001 From: mufazalov Date: Mon, 11 Mar 2024 13:44:23 +0300 Subject: [PATCH] fix(MetricChart): explicitly process error with html --- src/components/MetricChart/MetricChart.tsx | 9 +++++++-- src/components/MetricChart/i18n/en.json | 3 +++ src/components/MetricChart/i18n/index.ts | 7 +++++++ src/types/api/render.ts | 7 +++++-- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/components/MetricChart/i18n/en.json create mode 100644 src/components/MetricChart/i18n/index.ts diff --git a/src/components/MetricChart/MetricChart.tsx b/src/components/MetricChart/MetricChart.tsx index c3d82e640c..2ba40d1d7b 100644 --- a/src/components/MetricChart/MetricChart.tsx +++ b/src/components/MetricChart/MetricChart.tsx @@ -30,6 +30,7 @@ import { setChartDataWasNotLoaded, setChartError, } from './reducer'; +import i18n from './i18n'; import './MetricChart.scss'; @@ -181,14 +182,18 @@ export const MetricChart = ({ return; } - // In some cases error could be in response with 200 status code + // Response could be a plain html for ydb versions without charts support + // Or there could be an error in response with 200 status code // It happens when request is OK, but chart data cannot be returned due to some reason // Example: charts are not enabled in the DB ('GraphShard is not enabled' error) if (Array.isArray(response)) { const preparedData = convertResponse(response, metrics); dispatch(setChartData(preparedData)); } else { - const err = {statusText: response.error}; + const err = { + statusText: + typeof response === 'string' ? i18n('not-supported') : response.error, + }; throw err; } diff --git a/src/components/MetricChart/i18n/en.json b/src/components/MetricChart/i18n/en.json new file mode 100644 index 0000000000..7f2c67d1ad --- /dev/null +++ b/src/components/MetricChart/i18n/en.json @@ -0,0 +1,3 @@ +{ + "not-supported": "Charts are not supported on current ydb version" +} diff --git a/src/components/MetricChart/i18n/index.ts b/src/components/MetricChart/i18n/index.ts new file mode 100644 index 0000000000..bc8aea0b4d --- /dev/null +++ b/src/components/MetricChart/i18n/index.ts @@ -0,0 +1,7 @@ +import {registerKeysets} from '../../../utils/i18n'; + +import en from './en.json'; + +const COMPONENT = 'ydb-metric-chart'; + +export default registerKeysets(COMPONENT, {en}); diff --git a/src/types/api/render.ts b/src/types/api/render.ts index 09ccf959ca..fa63638d19 100644 --- a/src/types/api/render.ts +++ b/src/types/api/render.ts @@ -4,12 +4,15 @@ * source: https://github.com/ydb-platform/ydb/blob/main/ydb/core/viewer/json_render.h */ -export type JsonRenderResponse = +export type JsonRenderResponse = JsonRenderErrorResponse | MetricData[]; + +/** Response could be a plain html with 404 on ydb versions without charts support */ +type JsonRenderErrorResponse = | { error?: string; status?: string; } - | MetricData[]; + | string; export interface MetricData { datapoints: MetricDatapoint[];