Skip to content

Commit 065faee

Browse files
committed
fix: improve error handling in extended profile form processing
1 parent bc1faef commit 065faee

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

  • openedx/core/djangoapps/user_api/accounts

openedx/core/djangoapps/user_api/accounts/api.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ def _get_extended_profile_form_instance(
282282
user (User): User instance to associate with the extended profile
283283
field_errors (dict): Dictionary to collect validation errors if form creation fails
284284
285+
Raises:
286+
AccountUpdateError: If there is an error creating the extended profile form
287+
285288
Returns:
286289
Optional[forms.Form]: Extended profile form instance with user data, or None if
287290
no extended profile form is configured or creation fails
@@ -306,12 +309,7 @@ def _get_extended_profile_form_instance(
306309
logger.warning("Extended profile model not available: %s", str(e))
307310
return None
308311
except Exception as e: # pylint: disable=broad-exception-caught
309-
logger.error("Unexpected error creating custom form for user %s: %s", user.username, str(e))
310-
field_errors["extended_profile"] = {
311-
"developer_message": f"Error creating custom form: {str(e)}",
312-
"user_message": _("There was an error processing the extended profile information"),
313-
}
314-
return None
312+
raise AccountUpdateError(f"Error creating custom form: {str(e)}") from e
315313

316314

317315
def _validate_extended_profile_form_and_collect_errors(extended_profile_form: forms.Form, field_errors: dict) -> None:
@@ -321,17 +319,23 @@ def _validate_extended_profile_form_and_collect_errors(extended_profile_form: fo
321319
Args:
322320
extended_profile_form (forms.Form): The extended profile form to validate
323321
field_errors (dict): Dictionary to collect validation errors
324-
"""
325-
if not extended_profile_form.is_valid():
326-
logger.info("Extended profile form validation failed with errors: %s", extended_profile_form.errors)
327322
328-
for field_name, field_errors_list in extended_profile_form.errors.items():
329-
first_error = field_errors_list[0] if field_errors_list else "Unknown error"
330-
331-
field_errors[field_name] = {
332-
"developer_message": f"Error in extended profile field {field_name}: {first_error}",
333-
"user_message": str(first_error),
334-
}
323+
Raises:
324+
AccountUpdateError: If there is an error validating the extended profile form
325+
"""
326+
try:
327+
if not extended_profile_form.is_valid():
328+
logger.info("Extended profile form validation failed with errors: %s", extended_profile_form.errors)
329+
330+
for field_name, field_errors_list in extended_profile_form.errors.items():
331+
first_error = field_errors_list[0] if field_errors_list else "Unknown error"
332+
333+
field_errors[field_name] = {
334+
"developer_message": f"Error in extended profile field {field_name}: {first_error}",
335+
"user_message": str(first_error),
336+
}
337+
except Exception as error: # pylint: disable=broad-exception-caught
338+
raise AccountUpdateError(f"Error thrown when validating extended profile form: '{str(error)}'") from error
335339

336340

337341
def _validate_read_only_fields(user, data, field_errors):

0 commit comments

Comments
 (0)