Skip to content

Commit

Permalink
update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang committed Sep 4, 2020
1 parent 2979056 commit ebee553
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from flask import g, request, Response
from flask_appbuilder.api import expose, protect, rison, safe
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_babel import gettext as _
from marshmallow import ValidationError
from sqlalchemy.engine.url import make_url
from sqlalchemy.exc import (
Expand Down Expand Up @@ -571,17 +572,23 @@ def test_connection( # pylint: disable=too-many-return-statements
except (NoSuchModuleError, ModuleNotFoundError):
logger.info("Invalid driver")
driver_name = make_url(item.get("sqlalchemy_uri")).drivername
message = f"Could not load database driver: {driver_name}"
return self.response(400, message=message, driver_name=driver_name)
return self.response(
400,
message=_(f"Could not load database driver: {driver_name}"),
driver_name=driver_name,
)
except DatabaseSecurityUnsafeError as ex:
return self.response_422(message=ex)
except OperationalError:
logger.warning("Connection failed")
return self.response(
500, message="Connection failed, please check your connection settings"
500,
message=_("Connection failed, please check your connection settings"),
)
except Exception as ex: # pylint: disable=broad-except
logger.error("Unexpected error %s", type(ex).__name__)
return self.response_400(
message="Unexpected error occurred, please check your logs for details"
message=_(
"Unexpected error occurred, please check your logs for details"
)
)
2 changes: 1 addition & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ def testconn( # pylint: disable=too-many-return-statements,no-self-use
logger.warning("Stopped an unsafe database connection")
return json_error_response(_(str(ex)), 400)
except Exception as ex: # pylint: disable=broad-except
logger.error("Unexpected error %s", type(ex).__name__)
logger.warning("Unexpected error %s", type(ex).__name__)
return json_error_response(
_("Unexpected error occurred, please check your logs for details"), 400
)
Expand Down

0 comments on commit ebee553

Please sign in to comment.