mirror of
https://github.com/apache/superset.git
synced 2024-09-16 02:29:39 -04:00
chore: use exc_info to pass errors to log warnings (#20252)
* use exc_info to pass errors to log warnings * Update superset/views/base.py Co-authored-by: Beto Dealmeida <roberto@dealmeida.net> * Update superset/views/base.py Co-authored-by: Beto Dealmeida <roberto@dealmeida.net> Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
This commit is contained in:
parent
2a1dcaf09b
commit
f270e49c4b
@ -576,8 +576,8 @@ class Database(
|
|||||||
database=self, inspector=self.inspector, schema=schema
|
database=self, inspector=self.inspector, schema=schema
|
||||||
)
|
)
|
||||||
return [(table, schema) for table in tables]
|
return [(table, schema) for table in tables]
|
||||||
except Exception as ex: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
logger.warning(ex)
|
logger.warning("Get all table names in schema failed", exc_info=True)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@cache_util.memoized_func(
|
@cache_util.memoized_func(
|
||||||
@ -607,8 +607,8 @@ class Database(
|
|||||||
database=self, inspector=self.inspector, schema=schema
|
database=self, inspector=self.inspector, schema=schema
|
||||||
)
|
)
|
||||||
return [(view, schema) for view in views]
|
return [(view, schema) for view in views]
|
||||||
except Exception as ex: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
logger.warning(ex)
|
logger.warning("Get all view names failed", exc_info=True)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@cache_util.memoized_func(
|
@cache_util.memoized_func(
|
||||||
@ -777,8 +777,8 @@ class Database(
|
|||||||
view_names: List[str] = []
|
view_names: List[str] = []
|
||||||
try:
|
try:
|
||||||
view_names = dialect.get_view_names(connection=conn, schema=schema)
|
view_names = dialect.get_view_names(connection=conn, schema=schema)
|
||||||
except Exception as ex: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
logger.warning(ex)
|
logger.warning("Has view failed", exc_info=True)
|
||||||
return view_name in view_names
|
return view_name in view_names
|
||||||
|
|
||||||
def has_view(self, view_name: str, schema: Optional[str] = None) -> bool:
|
def has_view(self, view_name: str, schema: Optional[str] = None) -> bool:
|
||||||
|
@ -158,7 +158,7 @@ class AsyncQueryManager:
|
|||||||
try:
|
try:
|
||||||
return jwt.decode(token, self._jwt_secret, algorithms=["HS256"])
|
return jwt.decode(token, self._jwt_secret, algorithms=["HS256"])
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.warning(ex)
|
logger.warning("Parse jwt failed", exc_info=True)
|
||||||
raise AsyncQueryTokenException("Failed to parse token") from ex
|
raise AsyncQueryTokenException("Failed to parse token") from ex
|
||||||
|
|
||||||
def init_job(self, channel_id: str, user_id: Optional[str]) -> Dict[str, Any]:
|
def init_job(self, channel_id: str, user_id: Optional[str]) -> Dict[str, Any]:
|
||||||
|
@ -183,8 +183,8 @@ def api(f: Callable[..., FlaskResponse]) -> Callable[..., FlaskResponse]:
|
|||||||
def wraps(self: "BaseSupersetView", *args: Any, **kwargs: Any) -> FlaskResponse:
|
def wraps(self: "BaseSupersetView", *args: Any, **kwargs: Any) -> FlaskResponse:
|
||||||
try:
|
try:
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
except NoAuthorizationError as ex:
|
except NoAuthorizationError:
|
||||||
logger.warning(ex)
|
logger.warning("Api failed- no authorization", exc_info=True)
|
||||||
return json_error_response(get_error_msg(), status=401)
|
return json_error_response(get_error_msg(), status=401)
|
||||||
except Exception as ex: # pylint: disable=broad-except
|
except Exception as ex: # pylint: disable=broad-except
|
||||||
logger.exception(ex)
|
logger.exception(ex)
|
||||||
@ -206,7 +206,7 @@ def handle_api_exception(
|
|||||||
try:
|
try:
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
except SupersetSecurityException as ex:
|
except SupersetSecurityException as ex:
|
||||||
logger.warning(ex)
|
logger.warning("SupersetSecurityException", exc_info=True)
|
||||||
return json_errors_response(
|
return json_errors_response(
|
||||||
errors=[ex.error], status=ex.status, payload=ex.payload
|
errors=[ex.error], status=ex.status, payload=ex.payload
|
||||||
)
|
)
|
||||||
@ -214,7 +214,7 @@ def handle_api_exception(
|
|||||||
logger.warning(ex, exc_info=True)
|
logger.warning(ex, exc_info=True)
|
||||||
return json_errors_response(errors=ex.errors, status=ex.status)
|
return json_errors_response(errors=ex.errors, status=ex.status)
|
||||||
except SupersetErrorException as ex:
|
except SupersetErrorException as ex:
|
||||||
logger.warning(ex)
|
logger.warning("SupersetErrorException", exc_info=True)
|
||||||
return json_errors_response(errors=[ex.error], status=ex.status)
|
return json_errors_response(errors=[ex.error], status=ex.status)
|
||||||
except SupersetException as ex:
|
except SupersetException as ex:
|
||||||
if ex.status >= 500:
|
if ex.status >= 500:
|
||||||
@ -397,20 +397,20 @@ def get_error_level_from_status_code( # pylint: disable=invalid-name
|
|||||||
# SupersetErrorException or SupersetErrorsException
|
# SupersetErrorException or SupersetErrorsException
|
||||||
@superset_app.errorhandler(SupersetErrorException)
|
@superset_app.errorhandler(SupersetErrorException)
|
||||||
def show_superset_error(ex: SupersetErrorException) -> FlaskResponse:
|
def show_superset_error(ex: SupersetErrorException) -> FlaskResponse:
|
||||||
logger.warning(ex)
|
logger.warning("SupersetErrorException", exc_info=True)
|
||||||
return json_errors_response(errors=[ex.error], status=ex.status)
|
return json_errors_response(errors=[ex.error], status=ex.status)
|
||||||
|
|
||||||
|
|
||||||
@superset_app.errorhandler(SupersetErrorsException)
|
@superset_app.errorhandler(SupersetErrorsException)
|
||||||
def show_superset_errors(ex: SupersetErrorsException) -> FlaskResponse:
|
def show_superset_errors(ex: SupersetErrorsException) -> FlaskResponse:
|
||||||
logger.warning(ex)
|
logger.warning("SupersetErrorsException", exc_info=True)
|
||||||
return json_errors_response(errors=ex.errors, status=ex.status)
|
return json_errors_response(errors=ex.errors, status=ex.status)
|
||||||
|
|
||||||
|
|
||||||
# Redirect to login if the CSRF token is expired
|
# Redirect to login if the CSRF token is expired
|
||||||
@superset_app.errorhandler(CSRFError)
|
@superset_app.errorhandler(CSRFError)
|
||||||
def refresh_csrf_token(ex: CSRFError) -> FlaskResponse:
|
def refresh_csrf_token(ex: CSRFError) -> FlaskResponse:
|
||||||
logger.warning(ex)
|
logger.warning("Refresh CSRF token error", exc_info=True)
|
||||||
|
|
||||||
if request.is_json:
|
if request.is_json:
|
||||||
return show_http_exception(ex)
|
return show_http_exception(ex)
|
||||||
@ -420,7 +420,7 @@ def refresh_csrf_token(ex: CSRFError) -> FlaskResponse:
|
|||||||
|
|
||||||
@superset_app.errorhandler(HTTPException)
|
@superset_app.errorhandler(HTTPException)
|
||||||
def show_http_exception(ex: HTTPException) -> FlaskResponse:
|
def show_http_exception(ex: HTTPException) -> FlaskResponse:
|
||||||
logger.warning(ex)
|
logger.warning("HTTPException", exc_info=True)
|
||||||
if (
|
if (
|
||||||
"text/html" in request.accept_mimetypes
|
"text/html" in request.accept_mimetypes
|
||||||
and not config["DEBUG"]
|
and not config["DEBUG"]
|
||||||
@ -446,7 +446,7 @@ def show_http_exception(ex: HTTPException) -> FlaskResponse:
|
|||||||
# or SupersetErrorsException, with a specific status code and error type
|
# or SupersetErrorsException, with a specific status code and error type
|
||||||
@superset_app.errorhandler(CommandException)
|
@superset_app.errorhandler(CommandException)
|
||||||
def show_command_errors(ex: CommandException) -> FlaskResponse:
|
def show_command_errors(ex: CommandException) -> FlaskResponse:
|
||||||
logger.warning(ex)
|
logger.warning("CommandException", exc_info=True)
|
||||||
if "text/html" in request.accept_mimetypes and not config["DEBUG"]:
|
if "text/html" in request.accept_mimetypes and not config["DEBUG"]:
|
||||||
path = resource_filename("superset", "static/assets/500.html")
|
path = resource_filename("superset", "static/assets/500.html")
|
||||||
return send_file(path, cache_timeout=0), 500
|
return send_file(path, cache_timeout=0), 500
|
||||||
|
Loading…
Reference in New Issue
Block a user