@@ -218,6 +218,10 @@ def add_url(name, view_func, methods=('GET',)):
218
218
self ._cached_layout = None
219
219
self .routes = []
220
220
221
+ # add a handler for components suites errors to return 404
222
+ self .server .errorhandler (exceptions .InvalidResourceError )(
223
+ self ._invalid_resources_handler )
224
+
221
225
@property
222
226
def layout (self ):
223
227
return self ._layout
@@ -400,14 +404,14 @@ def _generate_meta_html(self):
400
404
# Serve the JS bundles for each package
401
405
def serve_component_suites (self , package_name , path_in_package_dist ):
402
406
if package_name not in self .registered_paths :
403
- raise Exception (
407
+ raise exceptions . InvalidResourceError (
404
408
'Error loading dependency.\n '
405
409
'"{}" is not a registered library.\n '
406
410
'Registered libraries are: {}'
407
411
.format (package_name , list (self .registered_paths .keys ())))
408
412
409
413
elif path_in_package_dist not in self .registered_paths [package_name ]:
410
- raise Exception (
414
+ raise exceptions . InvalidResourceError (
411
415
'"{}" is registered but the path requested is not valid.\n '
412
416
'The path requested: "{}"\n '
413
417
'List of registered paths: {}'
@@ -944,6 +948,9 @@ def add_resource(p, filepath):
944
948
elif f == 'favicon.ico' :
945
949
self ._favicon = path
946
950
951
+ def _invalid_resources_handler (self , err ):
952
+ return err .args [0 ], 404
953
+
947
954
def get_asset_url (self , path ):
948
955
asset = _get_asset_path (
949
956
self .config .requests_pathname_prefix ,
0 commit comments