You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/10/03 00:13:31 UTC

[superset] 03/05: Address comments.

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

commit 0a0627cfcf6c427a19d3b68592cd1de849240a15
Author: Beto Dealmeida <ro...@dealmeida.net>
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 7cb5f630b6..fed45b43f2 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
@@ -208,13 +207,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',
+});