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;
This commit is contained in:
parent
34616d6cd5
commit
cf721a50fa
1 changed files with 5 additions and 1 deletions
|
|
@ -101,6 +101,7 @@ class UserViewSet(
|
||||||
@method_decorator(ratelimit(key="ip", rate="2/h" if not DEBUG else "888/h"))
|
@method_decorator(ratelimit(key="ip", rate="2/h" if not DEBUG else "888/h"))
|
||||||
def activate(self, request):
|
def activate(self, request):
|
||||||
detail = ""
|
detail = ""
|
||||||
|
activation_error = None
|
||||||
try:
|
try:
|
||||||
uuid = urlsafe_base64_decode(request.data.get("uidb64")).decode()
|
uuid = urlsafe_base64_decode(request.data.get("uidb64")).decode()
|
||||||
user = User.objects.nocache().get(pk=uuid)
|
user = User.objects.nocache().get(pk=uuid)
|
||||||
|
|
@ -117,10 +118,13 @@ class UserViewSet(
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
user.is_verified = True
|
user.is_verified = True
|
||||||
user.save()
|
user.save()
|
||||||
except (TypeError, ValueError, OverflowError, User.DoesNotExist) as e:
|
except (TypeError, ValueError, OverflowError, User.DoesNotExist) as activation_error:
|
||||||
user = None
|
user = None
|
||||||
|
activation_error = activation_error
|
||||||
detail = str(traceback.format_exc())
|
detail = str(traceback.format_exc())
|
||||||
if user is None:
|
if user is None:
|
||||||
|
if DEBUG:
|
||||||
|
raise Exception from activation_error
|
||||||
return Response(
|
return Response(
|
||||||
{"error": _("activation link is invalid!"), "detail": detail},
|
{"error": _("activation link is invalid!"), "detail": detail},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue