Skip to content

Commit c449c92

Browse files
committed
errors
1 parent c4e67bf commit c449c92

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

services/web/server/src/simcore_service_webserver/products/_controller/rest_exceptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
exception_handling_decorator,
77
to_exceptions_handlers_map,
88
)
9-
from ..errors import ProductNotFoundError
9+
from ..errors import MissingStripeConfigError, ProductNotFoundError
1010

1111
_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
1212
ProductNotFoundError: HttpErrorInfo(
1313
status.HTTP_404_NOT_FOUND, "{product_name} was not found"
1414
),
15+
MissingStripeConfigError: HttpErrorInfo(
16+
status.HTTP_503_SERVICE_UNAVAILABLE, MissingStripeConfigError.msg_template
17+
),
1518
}
1619

1720

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ._repository import ProductRepository
1313
from .errors import (
1414
BelowMinimumPaymentError,
15+
MissingStripeConfigError,
1516
ProductNotFoundError,
1617
ProductPriceNotDefinedError,
1718
ProductTemplateNotFoundError,
@@ -116,8 +117,9 @@ async def get_product_stripe_info(
116117
or "missing!!" in product_stripe_info.stripe_price_id
117118
or "missing!!" in product_stripe_info.stripe_tax_rate_id
118119
):
119-
msg = f"Missing product stripe for product {product_name}"
120-
raise ValueError(msg)
120+
raise MissingStripeConfigError(
121+
product_name=product_name, product_stripe_info=product_stripe_info
122+
)
121123
return product_stripe_info
122124

123125

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from ..errors import WebServerBaseError
22

33

4-
class ProductError(WebServerBaseError, ValueError):
5-
...
4+
class ProductError(WebServerBaseError, ValueError): ...
65

76

87
class ProductNotFoundError(ProductError):
@@ -19,3 +18,7 @@ class BelowMinimumPaymentError(ProductError):
1918

2019
class ProductTemplateNotFoundError(ProductError):
2120
msg_template = "Missing template {template_name} for product"
21+
22+
23+
class MissingStripeConfigError(ProductError):
24+
msg_template = "Missing product stripe for product {product_name}"

services/web/server/tests/unit/with_dbs/04/products/test_products_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from models_library.products import ProductName
1111
from simcore_service_webserver.products import products_service
1212
from simcore_service_webserver.products._repository import ProductRepository
13-
from simcore_service_webserver.products.errors import ProductPriceNotDefinedError
13+
from simcore_service_webserver.products.errors import (
14+
MissingStripeConfigError,
15+
ProductPriceNotDefinedError,
16+
)
1417

1518

1619
@pytest.fixture
@@ -46,7 +49,7 @@ async def test_get_product_stripe_info(
4649
# this feature is currently setup from adminer by an operator
4750

4851
# default is not configured
49-
with pytest.raises(ValueError, match=default_product_name):
52+
with pytest.raises(MissingStripeConfigError, match=default_product_name):
5053
await products_service.get_product_stripe_info(
5154
app, product_name=default_product_name
5255
)

0 commit comments

Comments
 (0)