From cf721a50fa5b65a53eddf7165096a06a08d0b12e Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Wed, 28 May 2025 15:23:59 +0300 Subject: [PATCH] Features: 1) Add `activation_error` variable for enhanced error handling; 2) Raise detailed exception in debug mode during user activation failure; Fixes: 1) Capture and store specific activation errors for debugging purposes; Extra: 1) Minor cleanup in exception handling logic; --- vibes_auth/viewsets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vibes_auth/viewsets.py b/vibes_auth/viewsets.py index 1a9f61d8..a1819b57 100644 --- a/vibes_auth/viewsets.py +++ b/vibes_auth/viewsets.py @@ -101,6 +101,7 @@ class UserViewSet( @method_decorator(ratelimit(key="ip", rate="2/h" if not DEBUG else "888/h")) def activate(self, request): detail = "" + activation_error = None try: uuid = urlsafe_base64_decode(request.data.get("uidb64")).decode() user = User.objects.nocache().get(pk=uuid) @@ -117,10 +118,13 @@ class UserViewSet( user.is_active = True user.is_verified = True user.save() - except (TypeError, ValueError, OverflowError, User.DoesNotExist) as e: + except (TypeError, ValueError, OverflowError, User.DoesNotExist) as activation_error: user = None + activation_error = activation_error detail = str(traceback.format_exc()) if user is None: + if DEBUG: + raise Exception from activation_error return Response( {"error": _("activation link is invalid!"), "detail": detail}, status=status.HTTP_400_BAD_REQUEST,