ktmud commented on a change in pull request #10274:
URL: 
https://github.com/apache/incubator-superset/pull/10274#discussion_r454634613



##########
File path: superset/errors.py
##########
@@ -46,6 +47,23 @@ class SupersetErrorType(str, Enum):
     DATASOURCE_SECURITY_ACCESS_ERROR = "DATASOURCE_SECURITY_ACCESS_ERROR"
     MISSING_OWNERSHIP_ERROR = "MISSING_OWNERSHIP_ERROR"
 
+    # Other errors
+    BACKEND_TIMEOUT_ERROR = "BACKEND_TIMEOUT_ERROR"
+
+
+ERROR_TYPES_TO_ERROR_CODES_MAPPING = {
+    SupersetErrorType.BACKEND_TIMEOUT_ERROR: [
+        {
+            "code": 1000,
+            "message": _("Error 1000 - The datasource is too large to query."),
+        },
+        {
+            "code": 1001,
+            "message": _("Error 1001 - The database is under an unusual 
load."),
+        },
+    ]
+}

Review comment:
       They are indeed two entities, one is runtime exception, another is the 
result payload used by the API. But it doesn't mean the payload cannot be 
generated by exception itself.
   
   The improvement is that you don't have to manually generate the payload 
every time an exception occurs. You just store relevant information as 
top-level attributes on the Exception and some general error handlers will 
return a consistent payload whenever needed. The payload doesn't have to be UI 
specific. We can certainly return different payloads for storage and API by 
adding arguments to the `to_json` method, if that's what we want.
   
   I just find it weird that you had to initialize two classes in order to 
raise an API-conforming exception. We already use class inheritance for 
Exceptions and used the pattern extensively for `superset.commands.exceptions`, 
so I'm not sure an additional mixin to serialize the exception is that much of 
complexity.




----------------------------------------------------------------
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