Features: 1) Add detailed error traceback in activation error response;
Fixes: 1) Log complete error traceback for debugging activation failures; Extra: 1) Minor code adjustments and variable addition for error handling;
This commit is contained in:
parent
4e269dc801
commit
861010ae86
1 changed files with 4 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import traceback
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from secrets import compare_digest
|
from secrets import compare_digest
|
||||||
|
|
||||||
|
|
@ -99,6 +100,7 @@ class UserViewSet(
|
||||||
@action(detail=False, methods=["post"])
|
@action(detail=False, methods=["post"])
|
||||||
@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 = ""
|
||||||
try:
|
try:
|
||||||
uuid = urlsafe_base64_decode(request.data.get("uidb64")).decode()
|
uuid = urlsafe_base64_decode(request.data.get("uidb64")).decode()
|
||||||
user = User.objects.get(pk=uuid)
|
user = User.objects.get(pk=uuid)
|
||||||
|
|
@ -117,10 +119,10 @@ class UserViewSet(
|
||||||
user.save()
|
user.save()
|
||||||
except (TypeError, ValueError, OverflowError, User.DoesNotExist) as e:
|
except (TypeError, ValueError, OverflowError, User.DoesNotExist) as e:
|
||||||
user = None
|
user = None
|
||||||
logger.error(str(e))
|
detail = str(traceback.format_exc())
|
||||||
if user is None:
|
if user is None:
|
||||||
return Response(
|
return Response(
|
||||||
{"error": _("activation link is invalid!")},
|
{"error": _("activation link is invalid!"), "detail": detail},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue