Skip to content

Commit 98aa6b2

Browse files
committed
Add InvalidResourceError exception type, fix #393.
1 parent 846d071 commit 98aa6b2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

dash/dash.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def add_url(name, view_func, methods=('GET',)):
218218
self._cached_layout = None
219219
self.routes = []
220220

221+
# add a handler for components suites errors to return 404
222+
self.server.errorhandler(exceptions.InvalidResourceError)(
223+
self._invalid_resources_handler)
224+
221225
@property
222226
def layout(self):
223227
return self._layout
@@ -400,14 +404,14 @@ def _generate_meta_html(self):
400404
# Serve the JS bundles for each package
401405
def serve_component_suites(self, package_name, path_in_package_dist):
402406
if package_name not in self.registered_paths:
403-
raise Exception(
407+
raise exceptions.InvalidResourceError(
404408
'Error loading dependency.\n'
405409
'"{}" is not a registered library.\n'
406410
'Registered libraries are: {}'
407411
.format(package_name, list(self.registered_paths.keys())))
408412

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

951+
def _invalid_resources_handler(self, err):
952+
return err.args[0], 404
953+
947954
def get_asset_url(self, path):
948955
asset = _get_asset_path(
949956
self.config.requests_pathname_prefix,

dash/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ class InvalidCallbackReturnValue(CallbackException):
6060

6161
class InvalidConfig(DashException):
6262
pass
63+
64+
65+
class InvalidResourceError(DashException):
66+
pass

0 commit comments

Comments
 (0)