Skip to content

Commit 6f27e33

Browse files
committed
using new functions
1 parent 10940e6 commit 6f27e33

File tree

6 files changed

+20
-220
lines changed

6 files changed

+20
-220
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from .exceptions_handlers_base import create_decorator_from_exception_handler
1+
from .exceptions_handlers_base import async_try_except_decorator
22
from .exceptions_handlers_http_error_map import (
33
ExceptionToHttpErrorMap,
44
HttpErrorInfo,
5-
create_exception_handler_from_http_error_map,
5+
to_exceptions_handlers_map,
66
)
77

88
__all__: tuple[str, ...] = (
99
"ExceptionToHttpErrorMap",
1010
"HttpErrorInfo",
11-
"create_decorator_from_exception_handler",
12-
"create_exception_handler_from_http_error_map",
11+
"async_try_except_decorator",
12+
"to_exceptions_handlers_map",
1313
)
1414

1515
# nopycln: file

services/web/server/src/simcore_service_webserver/folders/_exceptions_handlers.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
from ..exceptions_handlers import (
66
ExceptionToHttpErrorMap,
77
HttpErrorInfo,
8-
create_decorator_from_exception_handler,
9-
create_exception_handler_from_http_error_map,
10-
)
11-
from ..projects.exceptions import (
12-
BaseProjectError,
13-
ProjectRunningConflictError,
14-
ProjectStoppingError,
8+
async_try_except_decorator,
9+
to_exceptions_handlers_map,
1510
)
11+
from ..projects.exceptions import ProjectRunningConflictError, ProjectStoppingError
1612
from ..workspaces.errors import (
1713
WorkspaceAccessForbiddenError,
1814
WorkspaceFolderInconsistencyError,
1915
WorkspaceNotFoundError,
20-
WorkspacesValueError,
2116
)
2217
from .errors import (
2318
FolderAccessForbiddenError,
@@ -70,8 +65,7 @@
7065
}
7166

7267

73-
handle_plugin_requests_exceptions = create_decorator_from_exception_handler(
74-
exception_types=(BaseProjectError, FoldersValueError, WorkspacesValueError),
75-
exception_handler=create_exception_handler_from_http_error_map(_TO_HTTP_ERROR_MAP),
68+
handle_plugin_requests_exceptions = async_try_except_decorator(
69+
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
7670
)
7771
# this is one decorator with a single exception handler

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
1212
from ..exceptions_handlers import (
1313
ExceptionToHttpErrorMap,
1414
HttpErrorInfo,
15-
create_decorator_from_exception_handler,
16-
create_exception_handler_from_http_error_map,
15+
async_try_except_decorator,
16+
to_exceptions_handlers_map,
1717
)
1818
from ..login.decorators import get_user_id, login_required
1919
from ..products.api import get_product_name
2020
from ..projects._common_models import ProjectPathParams
2121
from ..security.decorators import permission_required
2222
from . import _trash_api
2323
from ._common_models import RemoveQueryParams
24-
from .exceptions import (
25-
ProjectRunningConflictError,
26-
ProjectStoppingError,
27-
ProjectTrashError,
28-
)
24+
from .exceptions import ProjectRunningConflictError, ProjectStoppingError
2925

3026
_logger = logging.getLogger(__name__)
3127

@@ -46,9 +42,8 @@
4642
}
4743

4844

49-
_handle_exceptions = create_decorator_from_exception_handler(
50-
exception_types=ProjectTrashError,
51-
exception_handler=create_exception_handler_from_http_error_map(_TO_HTTP_ERROR_MAP),
45+
_handle_exceptions = async_try_except_decorator(
46+
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
5247
)
5348

5449

services/web/server/src/simcore_service_webserver/workspaces/_exceptions_handlers.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,19 @@
55
from ..exceptions_handlers import (
66
ExceptionToHttpErrorMap,
77
HttpErrorInfo,
8-
create_exception_handlers_decorator,
9-
)
10-
from ..projects.exceptions import (
11-
BaseProjectError,
12-
ProjectRunningConflictError,
13-
ProjectStoppingError,
8+
async_try_except_decorator,
9+
to_exceptions_handlers_map,
1410
)
11+
from ..projects.exceptions import ProjectRunningConflictError, ProjectStoppingError
1512
from .errors import (
1613
WorkspaceAccessForbiddenError,
1714
WorkspaceGroupNotFoundError,
1815
WorkspaceNotFoundError,
19-
WorkspacesValueError,
2016
)
2117

2218
_logger = logging.getLogger(__name__)
2319

2420

25-
def tr(msg) -> str:
26-
return msg
27-
28-
2921
_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
3022
WorkspaceGroupNotFoundError: HttpErrorInfo(
3123
status.HTTP_404_NOT_FOUND,
@@ -51,7 +43,6 @@ def tr(msg) -> str:
5143
}
5244

5345

54-
handle_plugin_requests_exceptions = create_exception_handlers_decorator(
55-
exceptions_catch=(BaseProjectError, WorkspacesValueError),
56-
exc_to_status_map=_TO_HTTP_ERROR_MAP,
46+
handle_plugin_requests_exceptions = async_try_except_decorator(
47+
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
5748
)

services/web/server/tests/unit/isolated/test_exceptions_handlers.py

Lines changed: 0 additions & 180 deletions
This file was deleted.

services/web/server/tests/unit/isolated/test_exceptions_handlers_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def _concrete_exc_handler(request, exception):
104104

105105

106106
@pytest.mark.parametrize("exception_cls", [OneError, OtherError])
107-
async def test_create_decorator_from_exception_handler(exception_cls: type[Exception]):
107+
async def test_async_try_except_decorator(exception_cls: type[Exception]):
108108
expected_request = make_mocked_request("GET", "/foo")
109109
expected_exception = exception_cls()
110110
expected_response = web.Response(reason=f"suppressed {exception_cls}")

0 commit comments

Comments
 (0)