Skip to content

Commit bb6c97f

Browse files
committed
nodes
1 parent 173e238 commit bb6c97f

File tree

2 files changed

+67
-34
lines changed

2 files changed

+67
-34
lines changed

services/web/server/src/simcore_service_webserver/projects/_common/exception_handlers.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from servicelib.aiohttp import status
4+
from servicelib.rabbitmq.rpc_interfaces.catalog.errors import CatalogForbiddenError
45

56
from ...exception_handling import (
67
ExceptionToHttpErrorMap,
@@ -9,13 +10,24 @@
910
to_exceptions_handlers_map,
1011
)
1112
from ...folders.errors import FolderAccessForbiddenError, FolderNotFoundError
13+
from ...resource_usage.errors import DefaultPricingPlanNotFoundError
14+
from ...users.exceptions import UserDefaultWalletNotFoundError
15+
from ...wallets.errors import WalletAccessForbiddenError, WalletNotEnoughCreditsError
1216
from ...workspaces.errors import WorkspaceAccessForbiddenError, WorkspaceNotFoundError
1317
from ..exceptions import (
18+
ClustersKeeperNotAvailableError,
19+
DefaultPricingUnitNotFoundError,
20+
NodeNotFoundError,
21+
ParentNodeNotFoundError,
1422
ProjectDeleteError,
1523
ProjectGroupNotFoundError,
24+
ProjectInDebtCanNotChangeWalletError,
1625
ProjectInvalidRightsError,
26+
ProjectInvalidUsageError,
27+
ProjectNodeRequiredInputsNotSetError,
1728
ProjectNotFoundError,
1829
ProjectOwnerNotFoundInTheProjectAccessRightsError,
30+
ProjectStartsTooManyDynamicNodesError,
1931
WrongTagIdsInQueryError,
2032
)
2133

@@ -33,6 +45,14 @@
3345
status.HTTP_404_NOT_FOUND,
3446
"Folder not found: {reason}",
3547
),
48+
NodeNotFoundError: HttpErrorInfo(
49+
status.HTTP_404_NOT_FOUND,
50+
"Node '{node_uuid}' not found in project '{project_uuid}'",
51+
),
52+
ParentNodeNotFoundError: HttpErrorInfo(
53+
status.HTTP_404_NOT_FOUND,
54+
"Parent node '{node_uuid}' not found",
55+
),
3656
ProjectDeleteError: HttpErrorInfo(
3757
status.HTTP_409_CONFLICT,
3858
"Failed to complete deletion of '{project_uuid}': {reason}",
@@ -45,6 +65,10 @@
4565
status.HTTP_403_FORBIDDEN,
4666
"Do not have sufficient access rights on project {project_uuid} for this action",
4767
),
68+
ProjectInvalidUsageError: HttpErrorInfo(
69+
status.HTTP_422_UNPROCESSABLE_ENTITY,
70+
"Invalid usage for project",
71+
),
4872
ProjectNotFoundError: HttpErrorInfo(
4973
status.HTTP_404_NOT_FOUND,
5074
"Project {project_uuid} not found",
@@ -65,8 +89,47 @@
6589
status.HTTP_400_BAD_REQUEST,
6690
"Wrong tag IDs in query",
6791
),
92+
UserDefaultWalletNotFoundError: HttpErrorInfo(
93+
status.HTTP_404_NOT_FOUND,
94+
"User default wallet not found",
95+
),
96+
DefaultPricingPlanNotFoundError: HttpErrorInfo(
97+
status.HTTP_404_NOT_FOUND,
98+
"Default pricing plan not found",
99+
),
100+
DefaultPricingUnitNotFoundError: HttpErrorInfo(
101+
status.HTTP_404_NOT_FOUND,
102+
"Default pricing unit not found",
103+
),
104+
WalletNotEnoughCreditsError: HttpErrorInfo(
105+
status.HTTP_402_PAYMENT_REQUIRED,
106+
"Wallet does not have enough credits. {reason}",
107+
),
108+
ProjectInDebtCanNotChangeWalletError: HttpErrorInfo(
109+
status.HTTP_402_PAYMENT_REQUIRED,
110+
"Unable to change the credit account linked to the project. The project is embargoed because the last transaction of {debt_amount} resulted in the credit account going negative.",
111+
),
112+
ProjectStartsTooManyDynamicNodesError: HttpErrorInfo(
113+
status.HTTP_409_CONFLICT,
114+
"The maximal amount of concurrently running dynamic services was reached. Please manually stop a service and retry.",
115+
),
116+
ClustersKeeperNotAvailableError: HttpErrorInfo(
117+
status.HTTP_503_SERVICE_UNAVAILABLE,
118+
"Clusters-keeper service is not available",
119+
),
120+
ProjectNodeRequiredInputsNotSetError: HttpErrorInfo(
121+
status.HTTP_409_CONFLICT,
122+
"Project node is required but input is not set",
123+
),
124+
CatalogForbiddenError: HttpErrorInfo(
125+
status.HTTP_403_FORBIDDEN,
126+
"Catalog forbidden: Insufficient access rights for {name}",
127+
),
128+
WalletAccessForbiddenError: HttpErrorInfo(
129+
status.HTTP_403_FORBIDDEN,
130+
"Payment required, but the user lacks access to the project's linked wallet: Wallet access forbidden. {reason}",
131+
),
68132
}
69-
70133
handle_plugin_requests_exceptions = exception_handling_decorator(
71134
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
72135
)

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- Get and Update methods only
1111
"""
1212

13-
import functools
1413
import logging
1514

1615
from aiohttp import web
@@ -22,50 +21,21 @@
2221
parse_request_body_as,
2322
parse_request_path_parameters_as,
2423
)
25-
from servicelib.aiohttp.typing_extension import Handler
2624
from servicelib.logging_utils import log_catch
2725

2826
from .._meta import api_version_prefix
2927
from ..login.decorators import login_required
3028
from ..security.decorators import permission_required
3129
from ..utils_aiohttp import envelope_json_response
3230
from . import _metadata_api
31+
from ._common.exception_handlers import handle_plugin_requests_exceptions
3332
from ._common.models import ProjectPathParams, RequestContext
34-
from .exceptions import (
35-
NodeNotFoundError,
36-
ParentNodeNotFoundError,
37-
ProjectInvalidRightsError,
38-
ProjectInvalidUsageError,
39-
ProjectNotFoundError,
40-
)
4133

4234
routes = web.RouteTableDef()
4335

4436
_logger = logging.getLogger(__name__)
4537

4638

47-
def _handle_project_exceptions(handler: Handler):
48-
"""Transforms project errors -> http errors"""
49-
50-
@functools.wraps(handler)
51-
async def wrapper(request: web.Request) -> web.StreamResponse:
52-
try:
53-
return await handler(request)
54-
55-
except (
56-
ProjectNotFoundError,
57-
NodeNotFoundError,
58-
ParentNodeNotFoundError,
59-
) as exc:
60-
raise web.HTTPNotFound(reason=f"{exc}") from exc
61-
except ProjectInvalidRightsError as exc:
62-
raise web.HTTPUnauthorized(reason=f"{exc}") from exc
63-
except ProjectInvalidUsageError as exc:
64-
raise web.HTTPUnprocessableEntity(reason=f"{exc}") from exc
65-
66-
return wrapper
67-
68-
6939
#
7040
# projects/*/custom-metadata
7141
#
@@ -77,7 +47,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
7747
)
7848
@login_required
7949
@permission_required("project.read")
80-
@_handle_project_exceptions
50+
@handle_plugin_requests_exceptions
8151
async def get_project_metadata(request: web.Request) -> web.Response:
8252
req_ctx = RequestContext.model_validate(request)
8353
path_params = parse_request_path_parameters_as(ProjectPathParams, request)
@@ -97,7 +67,7 @@ async def get_project_metadata(request: web.Request) -> web.Response:
9767
)
9868
@login_required
9969
@permission_required("project.update")
100-
@_handle_project_exceptions
70+
@handle_plugin_requests_exceptions
10171
async def update_project_metadata(request: web.Request) -> web.Response:
10272
req_ctx = RequestContext.model_validate(request)
10373
path_params = parse_request_path_parameters_as(ProjectPathParams, request)

0 commit comments

Comments
 (0)