style: apply ruff SIM108 ternary to validation error handling

This commit is contained in:
Johan Lundberg 2026-03-13 20:46:12 +01:00
parent 86deb56524
commit 752bf87b7c
No known key found for this signature in database
GPG key ID: A6C152738D03C7D1
2 changed files with 2 additions and 9 deletions

View file

@ -168,10 +168,7 @@ async def update_user_profile(
"locale": "Locale", "locale": "Locale",
} }
label = labels.get(str(field), str(field)) label = labels.get(str(field), str(field))
if error["type"] == "value_error": display_msg = msg.removeprefix("Value error, ") if error["type"] == "value_error" else f"{label}: {msg}"
display_msg = msg.removeprefix("Value error, ")
else:
display_msg = f"{label}: {msg}"
return HTMLResponse(f'<div role="alert">{display_msg}</div>') return HTMLResponse(f'<div role="alert">{display_msg}</div>')
user_repo = request.app.state.user_repo user_repo = request.app.state.user_repo

View file

@ -240,11 +240,7 @@ async def update_profile(
} }
label = labels.get(str(field), str(field)) label = labels.get(str(field), str(field))
# Use custom message for value errors (e.g. picture URL), generic pydantic message otherwise # Use custom message for value errors (e.g. picture URL), generic pydantic message otherwise
if error["type"] == "value_error": display_msg = msg.removeprefix("Value error, ") if error["type"] == "value_error" else f"{label}: {msg}"
# Strip Pydantic's "Value error, " prefix to get the original message
display_msg = msg.removeprefix("Value error, ")
else:
display_msg = f"{label}: {msg}"
return HTMLResponse(f'<div role="alert">{display_msg}</div>') return HTMLResponse(f'<div role="alert">{display_msg}</div>')
user_repo = request.app.state.user_repo user_repo = request.app.state.user_repo