Skip to content

Commit 8681fde

Browse files
committed
refactor request_product_account to improve error handling and validation
1 parent d254856 commit 8681fde

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
from typing import Any
33

44
from aiohttp import web
5+
from common_library.user_messages import user_message
56
from models_library.api_schemas_webserver.auth import (
67
AccountRequestInfo,
78
UnregisterCheck,
89
)
910
from servicelib.aiohttp import status
1011
from servicelib.aiohttp.application_keys import APP_FIRE_AND_FORGET_TASKS_KEY
11-
from servicelib.aiohttp.requests_validation import parse_request_body_as
12+
from servicelib.aiohttp.requests_validation import (
13+
handle_validation_as_http_error,
14+
parse_request_body_as,
15+
)
1216
from servicelib.logging_utils import get_log_record_extra, log_context
1317
from servicelib.utils import fire_and_forget_task
1418

@@ -88,10 +92,17 @@ async def request_product_account(request: web.Request):
8892
raise web.HTTPUnprocessableEntity(text=MSG_WRONG_CAPTCHA__INVALID)
8993
session.pop(CAPTCHA_SESSION_KEY, None)
9094

91-
# create pre-regiatration or raise if already exists
95+
with handle_validation_as_http_error(
96+
error_msg_template=user_message(
97+
"Found an error in the request form: '{failed}'"
98+
),
99+
resource_name=request.rel_url.path,
100+
):
101+
profile = UserAccountRestPreRegister.model_validate(body.form)
102+
92103
await _service.create_pre_registration(
93104
request.app,
94-
profile=UserAccountRestPreRegister.model_validate(body.form),
105+
profile=profile,
95106
product_name=product.name,
96107
)
97108

0 commit comments

Comments
 (0)