oncall-engine/engine/apps/phone_notifications/exceptions.py
Michael Derynck 7455966b89
Add a simple phone number ban mechanism (#4557)
# What this PR does

Add a simple list for maintaining phone numbers to restrict from SMS,
voice and verify. Works by removing the number as verified and block
future verification attempts with that number rather than check every
operation since all operations already check if a number is verified.

## Which issue(s) this PR closes

<!--
*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

- [x] 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.
2024-06-20 16:09:24 +00:00

54 lines
1.2 KiB
Python

class BaseFailed(Exception):
"""
Failed is base exception for all Failed... exceptions.
This exception is indicates error while performing some phone notification operation.
Optionally can contain graceful_msg attribute. When graceful_msg is provided it mean that error on provider side is
not our fault, but some provider error (number is blocked, fraud guard, ...).
By default, graceful_msg is None - it means that error is our fault (network problems, invalid configuration,...).
Attributes:
graceful_msg: string with some details about exception which can be exposed to caller.
"""
def __init__(self, graceful_msg=None):
self.graceful_msg = graceful_msg
class FailedToMakeCall(BaseFailed):
pass
class FailedToSendSMS(BaseFailed):
pass
class FailedToStartVerification(BaseFailed):
pass
class FailedToFinishVerification(BaseFailed):
pass
class NumberNotVerified(Exception):
pass
class NumberAlreadyVerified(Exception):
pass
class ProviderNotSupports(Exception):
pass
class CallsLimitExceeded(Exception):
pass
class SMSLimitExceeded(Exception):
pass
class PhoneNumberBanned(Exception):
pass