This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch sc_71594
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/sc_71594 by this push:
     new 4d5988edbf Address comments.
4d5988edbf is described below

commit 4d5988edbf93b0046dab92e429cb65bf1587ca24
Author: Beto Dealmeida <[email protected]>
AuthorDate: Fri Sep 15 12:12:40 2023 -0700

    Address comments.
---
 .../src/components/Datasource/DatasourceModal.test.jsx    |  2 +-
 .../src/components/Datasource/DatasourceModal.tsx         | 15 ++++++++-------
 superset-frontend/src/components/ErrorMessage/types.ts    |  9 +++++++++
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git 
a/superset-frontend/src/components/Datasource/DatasourceModal.test.jsx 
b/superset-frontend/src/components/Datasource/DatasourceModal.test.jsx
index 5bcb705b68..8f6948c25e 100644
--- a/superset-frontend/src/components/Datasource/DatasourceModal.test.jsx
+++ b/superset-frontend/src/components/Datasource/DatasourceModal.test.jsx
@@ -36,7 +36,7 @@ import { api } from 'src/hooks/apiResources/queryApi';
 const datasource = mockDatasource['7__table'];
 
 const SAVE_ENDPOINT = 'glob:*/api/v1/dataset/7';
-const SAVE_PAYLOAD = { new: 'data' };
+const SAVE_PAYLOAD = { json: () => ({ new: 'data' }) };
 const SAVE_DATASOURCE_ENDPOINT = 'glob:*/api/v1/dataset/7';
 const GET_DATASOURCE_ENDPOINT = SAVE_DATASOURCE_ENDPOINT;
 
diff --git a/superset-frontend/src/components/Datasource/DatasourceModal.tsx 
b/superset-frontend/src/components/Datasource/DatasourceModal.tsx
index 20cb5702b6..a36b09d287 100644
--- a/superset-frontend/src/components/Datasource/DatasourceModal.tsx
+++ b/superset-frontend/src/components/Datasource/DatasourceModal.tsx
@@ -31,7 +31,10 @@ import {
 
 import Modal from 'src/components/Modal';
 import AsyncEsmComponent from 'src/components/AsyncEsmComponent';
-import { SupersetError } from 'src/components/ErrorMessage/types';
+import {
+  genericSupersetError,
+  SupersetError,
+} from 'src/components/ErrorMessage/types';
 import ErrorMessageWithStackTrace from 
'src/components/ErrorMessage/ErrorMessageWithStackTrace';
 import withToasts from 'src/components/MessageToasts/withToasts';
 import { useSelector } from 'react-redux';
@@ -68,10 +71,6 @@ interface DatasourceModalProps {
   show: boolean;
 }
 
-interface ErrorResponse {
-  errors: SupersetError[];
-}
-
 function buildExtraJsonObject(item: Record<string, unknown>) {
   const certification =
     item?.certified_by || item?.certification_details
@@ -207,13 +206,15 @@ const DatasourceModal: 
FunctionComponent<DatasourceModalProps> = ({
       })
       .catch(response => {
         setIsSaving(false);
-        response.json().then((errorJson: ErrorResponse) => {
+        response.json().then((errorJson: { errors: SupersetError[] }) => {
           modal.error({
             title: t('Error saving dataset'),
             okButtonProps: { danger: true, className: 'btn-danger' },
             content: (
               <ErrorMessageWithStackTrace
-                error={errorJson.errors[0]}
+                error={
+                  errorJson?.errors?.[0] || genericSupersetError(errorJson)
+                }
                 source="crud"
               />
             ),
diff --git a/superset-frontend/src/components/ErrorMessage/types.ts 
b/superset-frontend/src/components/ErrorMessage/types.ts
index 7c4c3fe94a..c32435d7f4 100644
--- a/superset-frontend/src/components/ErrorMessage/types.ts
+++ b/superset-frontend/src/components/ErrorMessage/types.ts
@@ -107,3 +107,12 @@ export type ErrorMessageComponentProps<ExtraType = 
Record<string, any> | null> =
 
 export type ErrorMessageComponent =
   React.ComponentType<ErrorMessageComponentProps>;
+
+/* Generic error to be returned when the backend returns an error response 
that is not
+ * SIP-41 compliant. */
+export const genericSupersetError = (extra: object) => ({
+  error_type: ErrorTypeEnum.GENERIC_BACKEND_ERROR,
+  extra,
+  level: 'error' as ErrorLevel,
+  message: 'An error occurred',
+});

Reply via email to