Skip to content

Commit 2ef2191

Browse files
committed
updated errors
1 parent 55412c0 commit 2ef2191

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

services/web/server/src/simcore_service_webserver/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# pylint:disable=unused-import
22

3-
from sys import version
43
from typing import Final
54

65
from common_library.user_messages import user_message
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from common_library.user_messages import user_message
2+
from servicelib.aiohttp import status
3+
4+
from ....exception_handling import (
5+
ExceptionToHttpErrorMap,
6+
HttpErrorInfo,
7+
exception_handling_decorator,
8+
to_exceptions_handlers_map,
9+
)
10+
from ....users.exceptions import AlreadyPreRegisteredError
11+
from ..._constants import MSG_2FA_UNAVAILABLE
12+
from ...errors import SendingVerificationEmailError, SendingVerificationSmsError
13+
14+
_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
15+
AlreadyPreRegisteredError: HttpErrorInfo(
16+
status.HTTP_409_CONFLICT,
17+
user_message(
18+
"An account for the email {email} has been submitted. If you haven't received any updates, please contact support.",
19+
_version=1,
20+
),
21+
),
22+
SendingVerificationSmsError: HttpErrorInfo(
23+
status.HTTP_503_SERVICE_UNAVAILABLE,
24+
MSG_2FA_UNAVAILABLE,
25+
),
26+
SendingVerificationEmailError: HttpErrorInfo(
27+
status.HTTP_503_SERVICE_UNAVAILABLE,
28+
MSG_2FA_UNAVAILABLE,
29+
),
30+
}
31+
32+
33+
handle_rest_requests_exceptions = exception_handling_decorator(
34+
to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP)
35+
)

services/web/server/src/simcore_service_webserver/login/_controller/rest/auth.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
)
4040
from ..._models import InputSchema
4141
from ...decorators import login_required
42-
from ...errors import handle_login_exceptions
4342
from ...settings import LoginSettingsForProduct, get_plugin_settings
43+
from ._rest_exceptions import handle_rest_requests_exceptions
4444

4545
log = logging.getLogger(__name__)
4646

@@ -75,7 +75,7 @@ class LoginNextPage(NextPage[CodePageParams]): ...
7575
name="auth_resend_2fa_code",
7676
max_access_count=MAX_2FA_CODE_RESEND,
7777
)
78-
@handle_login_exceptions
78+
@handle_rest_requests_exceptions
7979
async def login(request: web.Request):
8080
"""Login: user submits an email (identification) and a password
8181
@@ -218,6 +218,7 @@ class LoginTwoFactorAuthBody(InputSchema):
218218
"auth_login_2fa",
219219
unauthorized_reason=MSG_UNAUTHORIZED_LOGIN_2FA,
220220
)
221+
@handle_rest_requests_exceptions
221222
async def login_2fa(request: web.Request):
222223
"""Login (continuation): Submits 2FA code"""
223224
product: Product = products_web.get_current_product(request)
@@ -266,6 +267,7 @@ class LogoutBody(InputSchema):
266267

267268
@routes.post(f"/{API_VTAG}/auth/logout", name="auth_logout")
268269
@login_required
270+
@handle_rest_requests_exceptions
269271
async def logout(request: web.Request) -> web.Response:
270272
user_id = request.get(RQT_USERID_KEY, -1)
271273

services/web/server/src/simcore_service_webserver/login/_controller/rest/twofa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from ..._login_repository_legacy import AsyncpgStorage, get_plugin_storage
2424
from ..._login_service import envelope_response
2525
from ..._models import InputSchema
26-
from ...errors import handle_login_exceptions
2726
from ...settings import LoginSettingsForProduct, get_plugin_settings
27+
from ._rest_exceptions import handle_rest_requests_exceptions
2828

2929
_logger = logging.getLogger(__name__)
3030

@@ -42,7 +42,7 @@ class Resend2faBody(InputSchema):
4242
name="auth_resend_2fa_code",
4343
one_time_access=False,
4444
)
45-
@handle_login_exceptions
45+
@handle_rest_requests_exceptions
4646
async def resend_2fa_code(request: web.Request):
4747
"""Resends 2FA code via SMS/Email"""
4848
product: Product = products_web.get_current_product(request)

services/web/server/tests/unit/with_dbs/03/login/test_login_preregistration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,5 @@ async def test_request_an_account(
219219
assert not user.registered
220220
assert user.status is None
221221
assert user.account_request_status == AccountRequestStatus.PENDING
222+
223+
# TODO add a test for reregistration `AlreadyPreRegisteredError`

0 commit comments

Comments
 (0)