Skip to content

Commit 9925abb

Browse files
committed
errors
1 parent 7421db2 commit 9925abb

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
"""
44

5-
import functools
65
import logging
76

87
from aiohttp import web
@@ -13,18 +12,17 @@
1312
from models_library.resource_tracker import PricingPlanId, PricingUnitId
1413
from pydantic import BaseModel, ConfigDict
1514
from servicelib.aiohttp.requests_validation import parse_request_path_parameters_as
16-
from servicelib.aiohttp.typing_extension import Handler
1715

1816
from .._meta import API_VTAG
1917
from ..login.decorators import login_required
2018
from ..resource_usage import service as rut_api
2119
from ..security.decorators import permission_required
2220
from ..utils_aiohttp import envelope_json_response
2321
from . import projects_service
22+
from ._common.exceptions_handlers import handle_plugin_requests_exceptions
2423
from ._common.models import RequestContext
2524
from ._nodes_handlers import NodePathParams
2625
from .db import ProjectDBAPI
27-
from .exceptions import ProjectInvalidRightsError, ProjectNotFoundError
2826

2927
_logger = logging.getLogger(__name__)
3028

@@ -37,21 +35,6 @@ class PricingUnitNotFoundError(PricingUnitError):
3735
msg_template = "Pricing unit not found"
3836

3937

40-
def _handle_projects_nodes_pricing_unit_exceptions(handler: Handler):
41-
@functools.wraps(handler)
42-
async def wrapper(request: web.Request) -> web.StreamResponse:
43-
try:
44-
return await handler(request)
45-
46-
except ProjectNotFoundError as exc:
47-
raise web.HTTPNotFound(reason=f"{exc}") from exc
48-
49-
except (PricingUnitNotFoundError, ProjectInvalidRightsError) as exc:
50-
raise web.HTTPForbidden(reason=f"{exc}") from exc
51-
52-
return wrapper
53-
54-
5538
routes = web.RouteTableDef()
5639

5740

@@ -61,7 +44,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
6144
)
6245
@login_required
6346
@permission_required("project.wallet.*")
64-
@_handle_projects_nodes_pricing_unit_exceptions
47+
@handle_plugin_requests_exceptions
6548
async def get_project_node_pricing_unit(request: web.Request):
6649
db: ProjectDBAPI = ProjectDBAPI.get_from_app_context(request.app)
6750
req_ctx = RequestContext.model_validate(request)
@@ -108,7 +91,7 @@ class _ProjectNodePricingUnitPathParams(BaseModel):
10891
)
10992
@login_required
11093
@permission_required("project.wallet.*")
111-
@_handle_projects_nodes_pricing_unit_exceptions
94+
@handle_plugin_requests_exceptions
11295
async def connect_pricing_unit_to_project_node(request: web.Request):
11396
db: ProjectDBAPI = ProjectDBAPI.get_from_app_context(request.app)
11497
req_ctx = RequestContext.model_validate(request)

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@
2424

2525
_logger = logging.getLogger(__name__)
2626

27-
#
28-
# LOCAL EXCEPTIONS HANDLING
29-
#
3027

31-
32-
_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
28+
_TRASH_ERRORS: ExceptionToHttpErrorMap = {
3329
ProjectRunningConflictError: HttpErrorInfo(
3430
status.HTTP_409_CONFLICT,
3531
"Current study is in use and cannot be trashed [project_id={project_uuid}]. Please stop all services first and try again",
@@ -40,16 +36,11 @@
4036
),
4137
}
4238

43-
4439
_handle_local_request_exceptions = exception_handling_decorator(
45-
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
40+
to_exceptions_handlers_map(_TRASH_ERRORS)
4641
)
4742

4843

49-
#
50-
# ROUTES
51-
#
52-
5344
routes = web.RouteTableDef()
5445

5546

0 commit comments

Comments
 (0)