Skip to content

Commit c0a6b2e

Browse files
BryanttVfeanil
authored andcommitted
refactor: enhance error handling in extended profile updates
1 parent 0378b47 commit c0a6b2e

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

  • openedx/core/djangoapps/user_api/accounts

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -424,24 +424,21 @@ def _update_extended_profile_if_needed(
424424
extended_profile.user = user_profile.user
425425
# Now persist the instance with the user field properly set
426426
extended_profile.save()
427-
except (ValidationError, IntegrityError, DatabaseError) as exc:
428-
error_messages = {
429-
ValidationError: (
430-
"Extended profile validation failed",
431-
_("The extended profile information could not be saved due to validation errors."),
432-
),
433-
IntegrityError: (
434-
"Extended profile integrity error",
435-
_("The extended profile information could not be saved. Please check for duplicate values."),
436-
),
437-
DatabaseError: (
438-
"Database error saving extended profile",
439-
_("The extended profile information could not be saved due to a system error."),
440-
),
441-
}
442-
dev_msg, user_msg = error_messages[type(exc)]
443-
raise AccountUpdateError(developer_message=f"{dev_msg}: {str(exc)}", user_message=user_msg) from exc
444-
427+
except ValidationError as exc:
428+
raise AccountUpdateError(
429+
developer_message=f"Extended profile validation failed: {str(exc)}",
430+
user_message=_("The extended profile information could not be saved due to validation errors."),
431+
) from exc
432+
except IntegrityError as exc:
433+
raise AccountUpdateError(
434+
developer_message=f"Extended profile integrity error: {str(exc)}",
435+
user_message=_("The extended profile information could not be saved. Please check for duplicate values."),
436+
) from exc
437+
except DatabaseError as exc:
438+
raise AccountUpdateError(
439+
developer_message=f"Database error saving extended profile: {str(exc)}",
440+
user_message=_("The extended profile information could not be saved due to a system error."),
441+
) from exc
445442

446443
def _update_state_if_needed(data, user_profile):
447444
# If the country was changed to something other than US, remove the state.

0 commit comments

Comments
 (0)