Skip to content

Commit

Permalink
If theme change fails, also log error message on the server and pass …
Browse files Browse the repository at this point in the history
…the ValidationError message to frontend
  • Loading branch information
mathjazz committed Dec 5, 2023
1 parent e6b4cc7 commit f70cf68
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pontoon/contributors/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging

from dateutil.relativedelta import relativedelta
from django.contrib import messages
Expand Down Expand Up @@ -26,6 +27,9 @@
from pontoon.uxactionlog.utils import log_ux_action


log = logging.getLogger(__name__)


@login_required(redirect_field_name="", login_url="/403")
def profile(request):
"""Current user profile."""
Expand Down Expand Up @@ -210,9 +214,11 @@ def toggle_theme(request, username):
profile.theme = theme
profile.full_clean()
profile.save()
except ValidationError:
except ValidationError as e:
error_message = f"User profile validation error: {e}"
log.error(error_message)
return JsonResponse(
{"status": False, "message": "Bad Request: Invalid theme"},
{"status": False, "message": error_message},
status=400,
)

Expand Down

0 comments on commit f70cf68

Please sign in to comment.