This is an automated email from the ASF dual-hosted git repository. michaelsmolina pushed a commit to branch 5.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 2df776e944632e7d56176fc72d801e2c228a0d9d Author: Elizabeth Thompson <[email protected]> AuthorDate: Thu Mar 6 10:58:22 2025 -0800 fix: Show response message as default error (#32507) (cherry picked from commit c2de749d0e116da422fb7abed1f1cfcc6ad6915d) --- superset-frontend/src/components/Chart/Chart.tsx | 11 +-- .../components/Chart/ChartErrorMessage.test.tsx | 84 ++++++++++++++++++++++ .../src/components/Chart/ChartErrorMessage.tsx | 10 ++- .../ErrorMessage/ErrorMessageWithStackTrace.tsx | 1 - 4 files changed, 94 insertions(+), 12 deletions(-) diff --git a/superset-frontend/src/components/Chart/Chart.tsx b/superset-frontend/src/components/Chart/Chart.tsx index 0389ebd309..94f521bcd1 100644 --- a/superset-frontend/src/components/Chart/Chart.tsx +++ b/superset-frontend/src/components/Chart/Chart.tsx @@ -24,7 +24,6 @@ import { logging, QueryFormData, styled, - ErrorTypeEnum, t, SqlaFormData, ClientErrorObject, @@ -240,15 +239,7 @@ class Chart extends PureComponent<ChartProps, {}> { height, datasetsStatus, } = this.props; - let error = queryResponse?.errors?.[0]; - if (error === undefined) { - error = { - error_type: ErrorTypeEnum.FRONTEND_NETWORK_ERROR, - level: 'error', - message: t('Check your network connection'), - extra: null, - }; - } + const error = queryResponse?.errors?.[0]; const message = chartAlert || queryResponse?.message; // if datasource is still loading, don't render JS errors diff --git a/superset-frontend/src/components/Chart/ChartErrorMessage.test.tsx b/superset-frontend/src/components/Chart/ChartErrorMessage.test.tsx new file mode 100644 index 0000000000..6d05a7b9df --- /dev/null +++ b/superset-frontend/src/components/Chart/ChartErrorMessage.test.tsx @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { render, screen } from 'spec/helpers/testing-library'; +import '@testing-library/jest-dom'; +import { ChartSource } from 'src/types/ChartSource'; +import { useChartOwnerNames } from 'src/hooks/apiResources'; +import { ResourceStatus } from 'src/hooks/apiResources/apiResources'; +import { ErrorType } from '@superset-ui/core'; +import { ChartErrorMessage } from './ChartErrorMessage'; +import { ErrorMessageComponentProps } from '../ErrorMessage/types'; +import getErrorMessageComponentRegistry from '../ErrorMessage/getErrorMessageComponentRegistry'; + +// Mock the useChartOwnerNames hook +jest.mock('src/hooks/apiResources', () => ({ + useChartOwnerNames: jest.fn(), +})); + +const mockUseChartOwnerNames = useChartOwnerNames as jest.MockedFunction< + typeof useChartOwnerNames +>; + +const ERROR_MESSAGE_COMPONENT = (props: ErrorMessageComponentProps) => ( + <> + <div>Test error</div> + <div>{props.subtitle}</div> + </> +); + +describe('ChartErrorMessage', () => { + const defaultProps = { + chartId: '1', + subtitle: 'Test subtitle', + source: 'test_source' as ChartSource, + }; + + it('renders the default error message when error is null', () => { + mockUseChartOwnerNames.mockReturnValue({ + result: null, + status: ResourceStatus.Loading, + error: null, + }); + render(<ChartErrorMessage {...defaultProps} />); + + expect(screen.getByText('Data error')).toBeInTheDocument(); + expect(screen.getByText('Test subtitle')).toBeInTheDocument(); + }); + + it('renders the error message that is passed in from the error', () => { + getErrorMessageComponentRegistry().registerValue( + 'VALID_KEY', + ERROR_MESSAGE_COMPONENT, + ); + render( + <ChartErrorMessage + {...defaultProps} + error={{ + error_type: 'VALID_KEY' as unknown as ErrorType, + message: 'Subtitle', + level: 'error', + extra: {}, + }} + />, + ); + + expect(screen.getByText('Test error')).toBeInTheDocument(); + expect(screen.getByText('Test subtitle')).toBeInTheDocument(); + }); +}); diff --git a/superset-frontend/src/components/Chart/ChartErrorMessage.tsx b/superset-frontend/src/components/Chart/ChartErrorMessage.tsx index 0454f1fe46..b6d3a85106 100644 --- a/superset-frontend/src/components/Chart/ChartErrorMessage.tsx +++ b/superset-frontend/src/components/Chart/ChartErrorMessage.tsx @@ -32,6 +32,8 @@ export type Props = { stackTrace?: string; } & Omit<ClientErrorObject, 'error'>; +const DEFAULT_CHART_ERROR = 'Data error'; + export const ChartErrorMessage: FC<Props> = ({ chartId, error, ...props }) => { // fetches the chart owners and adds them to the extra data of the error message const { result: owners } = useChartOwnerNames(chartId); @@ -42,5 +44,11 @@ export const ChartErrorMessage: FC<Props> = ({ chartId, error, ...props }) => { extra: { ...error.extra, owners }, }; - return <ErrorMessageWithStackTrace {...props} error={ownedError} />; + return ( + <ErrorMessageWithStackTrace + {...props} + error={ownedError} + title={DEFAULT_CHART_ERROR} + /> + ); }; diff --git a/superset-frontend/src/components/ErrorMessage/ErrorMessageWithStackTrace.tsx b/superset-frontend/src/components/ErrorMessage/ErrorMessageWithStackTrace.tsx index 9d36424574..b993927a7c 100644 --- a/superset-frontend/src/components/ErrorMessage/ErrorMessageWithStackTrace.tsx +++ b/superset-frontend/src/components/ErrorMessage/ErrorMessageWithStackTrace.tsx @@ -42,7 +42,6 @@ export default function ErrorMessageWithStackTrace({ title = DEFAULT_TITLE, error, subtitle, - copyText, link, stackTrace, source,
