From f70cf6863a890b8a06e4ba83e8a860f86894314c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matja=C5=BE=20Horvat?= Date: Tue, 5 Dec 2023 11:32:17 +0100 Subject: [PATCH] If theme change fails, also log error message on the server and pass the ValidationError message to frontend --- pontoon/contributors/views.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pontoon/contributors/views.py b/pontoon/contributors/views.py index 91e3a91105..4c2a4fda8d 100644 --- a/pontoon/contributors/views.py +++ b/pontoon/contributors/views.py @@ -1,4 +1,5 @@ import json +import logging from dateutil.relativedelta import relativedelta from django.contrib import messages @@ -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.""" @@ -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, )