etr2460 commented on a change in pull request #9753:
URL: 
https://github.com/apache/incubator-superset/pull/9753#discussion_r420968755



##########
File path: superset-frontend/src/components/ErrorMessage/types.ts
##########
@@ -17,18 +17,22 @@
  * under the License.
  */
 
-// TODO: Add more error types as we classify more errors
+// Keep in sync with superset/views/errors.py
 export const ErrorTypeEnum = {
-  // Generic errors created on the frontend
   FRONTEND_CSRF_ERROR: 'FRONTEND_CSRF_ERROR',
   FRONTEND_NETWORK_ERROR: 'FRONTEND_NETWORK_ERROR',
   FRONTEND_TIMEOUT_ERROR: 'FRONTEND_TIMEOUT_ERROR',
+

Review comment:
       I put the empty lines here to try and organize these errors into 
categories, since i expect there to be many of them going forward

##########
File path: superset/viz.py
##########
@@ -460,8 +462,19 @@ def get_df_payload(self, query_obj=None, **kwargs):
                     is_loaded = True
             except Exception as ex:
                 logger.exception(ex)
-                if not self.error_message:
-                    self.error_message = "{}".format(ex)
+
+                error = dataclasses.asdict(
+                    SupersetError(
+                        message="{}".format(ex),

Review comment:
       this was copy pasted from before, i assume `str(ex)` works the same way, 
so i'll change it

##########
File path: superset/errors.py
##########
@@ -0,0 +1,59 @@
+# 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.
+from dataclasses import dataclass
+from enum import Enum
+from typing import Any, Dict
+
+
+class SupersetErrorType(str, Enum):
+    """
+    Types of errors that can exist within Superset.
+
+    Keep in sync with superset-frontend/src/components/ErrorMessage/types.ts
+    """
+
+    FRONTEND_CSRF_ERROR = "FRONTEND_CSRF_ERROR"
+    FRONTEND_NETWORK_ERROR = "FRONTEND_NETWORK_ERROR"
+    FRONTEND_TIMEOUT_ERROR = "FRONTEND_TIMEOUT_ERROR"
+
+    GENERIC_DB_ENGINE_ERROR = "GENERIC_DB_ENGINE_ERROR"
+
+    VIZ_GET_DF_ERROR = "VIZ_GET_DF_ERROR"
+
+
+class ErrorLevel(str, Enum):
+    """
+    Levels of errors that can exist within Superset.
+
+    Keep in sync with superset-frontend/src/components/ErrorMessage/types.ts
+    """
+
+    INFO = "info"
+    WARNING = "warning"
+    ERROR = "error"
+
+
+@dataclass
+class SupersetError:
+    """
+    An error that is returned to a client.
+    """
+
+    message: str
+    error_type: SupersetErrorType
+    level: ErrorLevel
+    extra: Dict[str, Any]

Review comment:
       I went back and forth on that... I guess optional is probably safer in 
the long run, and means people don't need to remember to initialize with an 
empty dict, although it pushes a bit of work to the front end to check that the 
object exists

##########
File path: superset/viz.py
##########
@@ -460,8 +462,19 @@ def get_df_payload(self, query_obj=None, **kwargs):
                     is_loaded = True
             except Exception as ex:
                 logger.exception(ex)
-                if not self.error_message:
-                    self.error_message = "{}".format(ex)
+
+                error = dataclasses.asdict(
+                    SupersetError(
+                        message="{}".format(ex),
+                        level=ErrorLevel.ERROR,
+                        type=SupersetErrorType.VIZ_GET_DF_ERROR,
+                        extra={},
+                    )
+                )
+                if not self.errors:

Review comment:
       not sure how your previous comment would affect this




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to