Skip to content

Commit

Permalink
Add InvalidResourceError exception type, fix #393.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Sep 18, 2018
1 parent 846d071 commit 98aa6b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def add_url(name, view_func, methods=('GET',)):
self._cached_layout = None
self.routes = []

# add a handler for components suites errors to return 404
self.server.errorhandler(exceptions.InvalidResourceError)(
self._invalid_resources_handler)

@property
def layout(self):
return self._layout
Expand Down Expand Up @@ -400,14 +404,14 @@ def _generate_meta_html(self):
# Serve the JS bundles for each package
def serve_component_suites(self, package_name, path_in_package_dist):
if package_name not in self.registered_paths:
raise Exception(
raise exceptions.InvalidResourceError(
'Error loading dependency.\n'
'"{}" is not a registered library.\n'
'Registered libraries are: {}'
.format(package_name, list(self.registered_paths.keys())))

elif path_in_package_dist not in self.registered_paths[package_name]:
raise Exception(
raise exceptions.InvalidResourceError(
'"{}" is registered but the path requested is not valid.\n'
'The path requested: "{}"\n'
'List of registered paths: {}'
Expand Down Expand Up @@ -944,6 +948,9 @@ def add_resource(p, filepath):
elif f == 'favicon.ico':
self._favicon = path

def _invalid_resources_handler(self, err):
return err.args[0], 404

def get_asset_url(self, path):
asset = _get_asset_path(
self.config.requests_pathname_prefix,
Expand Down
4 changes: 4 additions & 0 deletions dash/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ class InvalidCallbackReturnValue(CallbackException):

class InvalidConfig(DashException):
pass


class InvalidResourceError(DashException):
pass

0 comments on commit 98aa6b2

Please sign in to comment.