Skip to content

Commit 32db0f4

Browse files
committed
fix tests
1 parent 00cfbd9 commit 32db0f4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

services/web/server/src/simcore_service_webserver/products/_web_helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from simcore_service_webserver.products.errors import (
99
FileTemplateNotFoundError,
1010
ProductNotFoundError,
11+
UnknownProductError,
1112
)
1213

1314
from .._resources import webserver_resources
@@ -19,7 +20,13 @@
1920

2021
def 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

3542
def _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

services/web/server/src/simcore_service_webserver/products/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
class ProductError(WebServerBaseError, ValueError): ...
55

66

7+
class UnknownProductError(ProductError):
8+
msg_template = "Cannot determine which is the product in the current context"
9+
10+
711
class ProductNotFoundError(ProductError):
812
msg_template = "Undefined product '{product_name}'"
913

0 commit comments

Comments
 (0)