From 63663b202dcd71511c0e95a07e37ee8cd5220649 Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Tue, 25 Jun 2024 15:31:57 -0600 Subject: [PATCH] Fix PhoneNumberBanned producing status code 500 (#4570) # What this PR does Handle PhoneNumberBanned as status code 403 instead of 500 ## Which issue(s) this PR closes Closes [issue link here] ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --------- Co-authored-by: Joey Orlando --- engine/apps/api/views/user.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engine/apps/api/views/user.py b/engine/apps/api/views/user.py index e0ee7414..940e08a6 100644 --- a/engine/apps/api/views/user.py +++ b/engine/apps/api/views/user.py @@ -59,6 +59,7 @@ from apps.phone_notifications.exceptions import ( FailedToStartVerification, NumberAlreadyVerified, NumberNotVerified, + PhoneNumberBanned, ProviderNotSupports, ) from apps.phone_notifications.phone_backend import PhoneBackend @@ -478,6 +479,8 @@ class UserView( phone_backend.send_verification_sms(user) except NumberAlreadyVerified: return Response("Phone number already verified", status=status.HTTP_400_BAD_REQUEST) + except PhoneNumberBanned: + return Response("Phone number has been banned", status=status.HTTP_403_FORBIDDEN) except FailedToStartVerification as e: return handle_phone_notificator_failed(e) except ProviderNotSupports: @@ -505,6 +508,8 @@ class UserView( phone_backend.make_verification_call(user) except NumberAlreadyVerified: return Response("Phone number already verified", status=status.HTTP_400_BAD_REQUEST) + except PhoneNumberBanned: + return Response("Phone number has been banned", status=status.HTTP_403_FORBIDDEN) except FailedToStartVerification as e: return handle_phone_notificator_failed(e) except ProviderNotSupports: