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]

<!--
*Note*: if you have more than one GitHub issue that this PR closes, be
sure to preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## 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 <joey.orlando@grafana.com>
This commit is contained in:
Michael Derynck 2024-06-25 15:31:57 -06:00 committed by GitHub
parent d583727c05
commit 63663b202d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: