Skip to content

Commit

Permalink
chore: return 404 instead of 500 for datasource not found (apache#22333)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh authored Dec 6, 2022
1 parent 04b7a26 commit 2f23a9c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions superset/charts/data/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from superset.charts.schemas import ChartDataQueryContextSchema
from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType
from superset.connectors.base.models import BaseDatasource
from superset.dao.exceptions import DatasourceNotFound
from superset.exceptions import QueryObjectValidationError
from superset.extensions import event_logger
from superset.utils.async_query_manager import AsyncQueryTokenException
Expand Down Expand Up @@ -141,6 +142,8 @@ def get_data(self, pk: int) -> Response:
query_context = self._create_query_context_from_form(json_body)
command = ChartDataCommand(query_context)
command.validate()
except DatasourceNotFound as error:
return self.response_404()
except QueryObjectValidationError as error:
return self.response_400(message=error.message)
except ValidationError as error:
Expand Down Expand Up @@ -229,6 +232,8 @@ def data(self) -> Response:
query_context = self._create_query_context_from_form(json_body)
command = ChartDataCommand(query_context)
command.validate()
except DatasourceNotFound as error:
return self.response_404()
except QueryObjectValidationError as error:
return self.response_400(message=error.message)
except ValidationError as error:
Expand Down

0 comments on commit 2f23a9c

Please sign in to comment.