Skip to content

Commit eabf2fa

Browse files
committed
refactor: streamline exception handling and improve service retrieval logic
1 parent 560fb37 commit eabf2fa

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

services/web/server/src/simcore_service_webserver/catalog/_controller_rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from ..utils_aiohttp import envelope_json_response
3838
from . import _catalog_rest_client_service, _service
3939
from ._controller_rest_exceptions import (
40-
DefaultPricingUnitForServiceNotFoundError,
4140
handle_plugin_requests_exceptions,
4241
)
4342
from ._controller_rest_schemas import (
@@ -50,6 +49,7 @@
5049
ServiceTagPathParams,
5150
ToServiceInputsQueryParams,
5251
)
52+
from .errors import DefaultPricingUnitForServiceNotFoundError
5353

5454
_logger = logging.getLogger(__name__)
5555

services/web/server/src/simcore_service_webserver/catalog/_controller_rest_exceptions.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,12 @@ async def _handler_catalog_client_errors(
105105
}
106106

107107

108-
_exceptions_handlers_map: ExceptionHandlersMap = {
108+
catalog_exceptions_handlers_map: ExceptionHandlersMap = {
109109
CatalogResponseError: _handler_catalog_client_errors,
110110
CatalogConnectionError: _handler_catalog_client_errors,
111111
}
112-
_exceptions_handlers_map.update(to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP))
112+
catalog_exceptions_handlers_map.update(to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP))
113113

114114
handle_plugin_requests_exceptions = exception_handling_decorator(
115-
_exceptions_handlers_map
116-
)
117-
118-
119-
__all__: tuple[str, ...] = (
120-
"CatalogForbiddenError",
121-
"CatalogItemNotFoundError",
122-
"DefaultPricingUnitForServiceNotFoundError",
115+
catalog_exceptions_handlers_map
123116
)

services/web/server/src/simcore_service_webserver/projects/_controller/_rest_exceptions.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
CatalogItemNotFoundError,
99
CatalogNotAvailableError,
1010
)
11+
from simcore_service_webserver.exception_handling._base import ExceptionHandlersMap
1112

13+
from ...catalog._controller_rest_exceptions import catalog_exceptions_handlers_map
1214
from ...conversations.errors import (
1315
ConversationErrorNotFoundError,
1416
ConversationMessageErrorNotFoundError,
@@ -239,6 +241,9 @@ def _assert_duplicate():
239241
}
240242

241243

242-
handle_plugin_requests_exceptions = exception_handling_decorator(
243-
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
244-
)
244+
_handlers: ExceptionHandlersMap = {
245+
**catalog_exceptions_handlers_map,
246+
**to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP),
247+
}
248+
249+
handle_plugin_requests_exceptions = exception_handling_decorator(_handlers)

services/web/server/src/simcore_service_webserver/projects/_crud_api_read.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ async def list_projects( # pylint: disable=too-many-arguments
120120
) -> tuple[list[ProjectDict], int]:
121121
db = ProjectDBAPI.get_from_app_context(app)
122122

123-
user_available_services: list[ServiceKeyVersionDict] = (
124-
await catalog_service.get_services_for_user_in_product(
125-
app, user_id=user_id, product_name=product_name
126-
)
123+
user_available_services = await catalog_service.get_services_for_user_in_product(
124+
app, user_id=user_id, product_name=product_name
127125
)
128126

129127
workspace_is_private = True
@@ -204,10 +202,8 @@ async def list_projects_full_depth(
204202
) -> tuple[list[ProjectDict], int]:
205203
db = ProjectDBAPI.get_from_app_context(app)
206204

207-
user_available_services: list[ServiceKeyVersionDict] = (
208-
await catalog_service.get_services_for_user_in_product(
209-
app, user_id=user_id, product_name=product_name
210-
)
205+
user_available_services = await catalog_service.get_services_for_user_in_product(
206+
app, user_id=user_id, product_name=product_name
211207
)
212208

213209
db_projects, db_project_types, total_number_projects = await db.list_projects_dicts(

0 commit comments

Comments
 (0)