File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
services/web/server/src/simcore_service_webserver/products Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 88from simcore_service_webserver .products .errors import (
99 FileTemplateNotFoundError ,
1010 ProductNotFoundError ,
11+ UnknownProductError ,
1112)
1213
1314from .._resources import webserver_resources
1920
2021def get_product_name (request : web .Request ) -> str :
2122 """Returns product name in request but might be undefined"""
22- product_name : str = request [RQ_PRODUCT_KEY ]
23+ # NOTE: introduced by middleware
24+ try :
25+ product_name : str = request [RQ_PRODUCT_KEY ]
26+ except KeyError as exc :
27+ error = UnknownProductError ()
28+ error .add_note ("TIP: Check products middleware" )
29+ raise error from exc
2330 return product_name
2431
2532
@@ -33,7 +40,7 @@ def get_current_product(request: web.Request) -> Product:
3340
3441
3542def _get_current_product_or_none (request : web .Request ) -> Product | None :
36- with contextlib .suppress (ProductNotFoundError , KeyError ):
43+ with contextlib .suppress (ProductNotFoundError , UnknownProductError ):
3744 product : Product = get_current_product (request )
3845 return product
3946 return None
Original file line number Diff line number Diff line change 44class ProductError (WebServerBaseError , ValueError ): ...
55
66
7+ class UnknownProductError (ProductError ):
8+ msg_template = "Cannot determine which is the product in the current context"
9+
10+
711class ProductNotFoundError (ProductError ):
812 msg_template = "Undefined product '{product_name}'"
913
You can’t perform that action at this time.
0 commit comments