Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 404 from serve_components_suites when the path is not registered. #394

Merged
merged 2 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## 0.26.6 - 2018-09-18
## 0.26.6 - 2018-09-19
## Fixed
- Added `Cache-Control` headers to files served by `Dash.serve_components_suites`. [#387](https://github.com/plotly/dash/pull/387)
- Added `Cache-Control` headers to files served by `Dash.serve_component_suites`. [#387](https://github.com/plotly/dash/pull/387)
- Added time modified query string to collected components suites resources.
- Added `InvalidResourceError`. [#393](https://github.com/plotly/dash/pull/393)
- Added a flask errorhandler to catch `InvalidResourceError` from `serve_component_suites` and return a 404.

## 0.26.5 - 2018-09-10
## Fixed
Expand Down
11 changes: 9 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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 @@ -411,14 +415,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 @@ -962,6 +966,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