This is an automated email from the ASF dual-hosted git repository. erikrit pushed a commit to branch erik-ritter--chart-data-api-error-handling in repository https://gitbox.apache.org/repos/asf/superset.git
commit b659cf37b2b9ac805490e98e862887aa886499d2 Author: erik_ritter <erik.rit...@airbnb.com> AuthorDate: Thu Apr 8 16:50:46 2021 -0700 feat: handle chart/data API errors --- superset/charts/api.py | 7 ------- superset/exceptions.py | 27 ++++++++++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/superset/charts/api.py b/superset/charts/api.py index 20ea943..dbeb34a 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -500,7 +500,6 @@ class ChartRestApi(BaseSupersetModelRestApi): @expose("/data", methods=["POST"]) @protect() - @safe @statsd_metrics @event_logger.log_this_with_context( action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.data", @@ -569,8 +568,6 @@ class ChartRestApi(BaseSupersetModelRestApi): "Request is incorrect: %(error)s", error=error.normalized_messages() ) ) - except SupersetSecurityException: - return self.response_401() # TODO: support CSV, SQL query and other non-JSON types if ( @@ -591,7 +588,6 @@ class ChartRestApi(BaseSupersetModelRestApi): @expose("/data/<cache_key>", methods=["GET"]) @protect() - @safe @statsd_metrics @event_logger.log_this_with_context( action=lambda self, *args, **kwargs: f"{self.__class__.__name__}" @@ -641,9 +637,6 @@ class ChartRestApi(BaseSupersetModelRestApi): return self.response_400( message=_("Request is incorrect: %(error)s", error=error.messages) ) - except SupersetSecurityException as exc: - logger.info(exc) - return self.response_401() return self.get_data_response(command, True) diff --git a/superset/exceptions.py b/superset/exceptions.py index 42e089b..951ce22 100644 --- a/superset/exceptions.py +++ b/superset/exceptions.py @@ -43,15 +43,25 @@ class SupersetErrorException(SupersetException): def __init__( self, + error: SupersetError + ) -> None: + super().__init__(error.message) + self.error = error + + +class SupersetErrorFromParamsException(SupersetErrorException): + """Exceptions that pass in parameters to construct a SupersetError""" + + def __init__( + self, error_type: SupersetErrorType, message: str, level: ErrorLevel, extra: Optional[Dict[str, Any]] = None, ) -> None: - super().__init__(message) - self.error = SupersetError( + super().__init__(SupersetError( error_type=error_type, message=message, level=level, extra=extra or {} - ) + )) class SupersetErrorsException(SupersetException): @@ -62,11 +72,11 @@ class SupersetErrorsException(SupersetException): self.errors = errors -class SupersetTimeoutException(SupersetErrorException): +class SupersetTimeoutException(SupersetErrorFromParamsException): status = 408 -class SupersetGenericDBErrorException(SupersetErrorException): +class SupersetGenericDBErrorException(SupersetErrorFromParamsException): status = 400 def __init__( @@ -80,7 +90,7 @@ class SupersetGenericDBErrorException(SupersetErrorException): ) -class SupersetTemplateParamsErrorException(SupersetErrorException): +class SupersetTemplateParamsErrorException(SupersetErrorFromParamsException): status = 400 def __init__( @@ -94,14 +104,13 @@ class SupersetTemplateParamsErrorException(SupersetErrorException): ) -class SupersetSecurityException(SupersetException): +class SupersetSecurityException(SupersetErrorException): status = 401 def __init__( self, error: SupersetError, payload: Optional[Dict[str, Any]] = None ) -> None: - super().__init__(error.message) - self.error = error + super().__init__(error) self.payload = payload