Added new exception class and start of better exception/error handling (#4514)
* rebase and linting * change back * wip * fixed broken test * fix flake8 * fix test
This commit is contained in:
parent
ff41f40721
commit
2bc089ef8d
|
|
@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from flask import Markup
|
||||
|
||||
from superset.utils import SupersetException
|
||||
from superset.exceptions import SupersetException
|
||||
from superset.views.base import SupersetModelView
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,11 +35,12 @@ from sqlalchemy.orm import backref, relationship
|
|||
|
||||
from superset import conf, db, import_util, sm, utils
|
||||
from superset.connectors.base.models import BaseColumn, BaseDatasource, BaseMetric
|
||||
from superset.exceptions import MetricPermException
|
||||
from superset.models.helpers import (
|
||||
AuditMixinNullable, ImportMixin, QueryResult, set_perm,
|
||||
)
|
||||
from superset.utils import (
|
||||
DimSelector, DTTM_ALIAS, flasher, MetricPermException,
|
||||
DimSelector, DTTM_ALIAS, flasher,
|
||||
)
|
||||
|
||||
DRUID_TZ = conf.get('DRUID_TZ')
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ import unicodecsv
|
|||
from werkzeug.utils import secure_filename
|
||||
|
||||
from superset import app, cache_util, conf, db, utils
|
||||
from superset.utils import QueryStatus, SupersetTemplateException
|
||||
from superset.exceptions import SupersetTemplateException
|
||||
from superset.utils import QueryStatus
|
||||
|
||||
config = app.config
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
class SupersetException(Exception):
|
||||
status = 500
|
||||
|
||||
|
||||
class SupersetTimeoutException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class SupersetSecurityException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class MetricPermException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class NoDataException(SupersetException):
|
||||
status = 400
|
||||
|
||||
|
||||
class SupersetTemplateException(SupersetException):
|
||||
pass
|
||||
|
|
@ -45,6 +45,8 @@ import sqlalchemy as sa
|
|||
from sqlalchemy import event, exc, select
|
||||
from sqlalchemy.types import TEXT, TypeDecorator
|
||||
|
||||
from superset.exceptions import SupersetException, SupersetTimeoutException
|
||||
|
||||
|
||||
logging.getLogger('MARKDOWN').setLevel(logging.INFO)
|
||||
|
||||
|
|
@ -53,30 +55,6 @@ EPOCH = datetime(1970, 1, 1)
|
|||
DTTM_ALIAS = '__timestamp'
|
||||
|
||||
|
||||
class SupersetException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SupersetTimeoutException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class SupersetSecurityException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class MetricPermException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class NoDataException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
class SupersetTemplateException(SupersetException):
|
||||
pass
|
||||
|
||||
|
||||
def can_access(sm, permission_name, view_name, user):
|
||||
"""Protecting from has_access failing from missing perms/view"""
|
||||
if user.is_anonymous():
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ from superset import (
|
|||
)
|
||||
from superset.connectors.connector_registry import ConnectorRegistry
|
||||
from superset.connectors.sqla.models import AnnotationDatasource, SqlaTable
|
||||
from superset.exceptions import SupersetException, SupersetSecurityException
|
||||
from superset.forms import CsvToDatabaseForm
|
||||
from superset.legacy import cast_form_data
|
||||
import superset.models.core as models
|
||||
|
|
@ -115,7 +116,7 @@ def check_ownership(obj, raise_if_false=True):
|
|||
if not obj:
|
||||
return False
|
||||
|
||||
security_exception = utils.SupersetSecurityException(
|
||||
security_exception = SupersetSecurityException(
|
||||
"You don't have the rights to alter [{}]".format(obj))
|
||||
|
||||
if g.user.is_anonymous():
|
||||
|
|
@ -1099,6 +1100,10 @@ class Superset(BaseSupersetView):
|
|||
|
||||
try:
|
||||
payload = viz_obj.get_payload()
|
||||
except SupersetException as se:
|
||||
logging.exception(se)
|
||||
return json_error_response(utils.error_msg_from_exception(se),
|
||||
status=se.status)
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
return json_error_response(utils.error_msg_from_exception(e))
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ from six.moves import cPickle as pkl, reduce
|
|||
from superset import app, cache, get_manifest_file, utils
|
||||
from superset.utils import DTTM_ALIAS, merge_extra_filters
|
||||
|
||||
|
||||
config = app.config
|
||||
stats_logger = config.get('STATS_LOGGER')
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ import uuid
|
|||
from mock import patch
|
||||
import numpy
|
||||
|
||||
from superset.exceptions import SupersetException
|
||||
from superset.utils import (
|
||||
base_json_conv, datetime_f, json_int_dttm_ser, json_iso_dttm_ser,
|
||||
JSONEncodedDict, memoized, merge_extra_filters, merge_request_params,
|
||||
parse_human_timedelta,
|
||||
SupersetException, validate_json, zlib_compress, zlib_decompress_to_string,
|
||||
parse_human_timedelta, validate_json, zlib_compress, zlib_decompress_to_string,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue