Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomedina248 committed Jun 27, 2022
1 parent cf64245 commit 9fb87b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions superset/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def __init__(
self.status = status


class SupersetSyntaxErrorException(SupersetErrorsException):
status = 422
error_type = SupersetErrorType.SYNTAX_ERROR

def __init__(self, errors: List[SupersetError]) -> None:
super().__init__(errors)


class SupersetTimeoutException(SupersetErrorFromParamsException):
status = 408

Expand Down
15 changes: 12 additions & 3 deletions superset/sqllab/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
from superset.commands.base import BaseCommand
from superset.common.db_query_status import QueryStatus
from superset.dao.exceptions import DAOCreateFailedError
from superset.errors import SupersetErrorType
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.exceptions import (
SupersetErrorsException,
SupersetException,
SupersetGenericErrorException,
SupersetSyntaxErrorException,
)
from superset.models.core import Database
from superset.models.sql_lab import Query
Expand Down Expand Up @@ -116,11 +117,19 @@ def run( # pylint: disable=too-many-statements,useless-suppression
}
except SupersetErrorsException as ex:
if all(ex.error_type == SupersetErrorType.SYNTAX_ERROR for ex in ex.errors):
ex.status = 422
raise SupersetSyntaxErrorException(ex.errors) from ex
raise ex
except SupersetException as ex:
if ex.error_type == SupersetErrorType.SYNTAX_ERROR:
ex.status = 422
raise SupersetSyntaxErrorException(
[
SupersetError(
message=ex.message,
error_type=ex.error_type,
level=ErrorLevel.ERROR,
)
]
) from ex
raise ex
except Exception as ex:
raise SqlLabException(self._execution_context, exception=ex) from ex
Expand Down

0 comments on commit 9fb87b1

Please sign in to comment.