Remove per-client SMS exception classes

In response to: [^1].

The stacktrace conveys the same and more information. We don't do
anything different for each exception class, so there's no value
in having three of them over one exception.

I did think about DRYing-up the duplicate exception behaviour into
the base class one. This isn't ideal because the base class would
be making assumptions about how inheriting classes make requests,
which might change with future providers. Although it might be nice
to have more info in the top-level message, we'll still get it in
the stacktrace e.g.

    ValueError: Expected 'code' to be '0'
    During handling of the above exception, another exception occurred:
    app.clients.sms.SmsClientResponseException: SMS client error (Invalid response JSON)

    requests.exceptions.ReadTimeout
    During handling of the above exception, another exception occurred:
    app.clients.sms.SmsClientResponseException: SMS client error (Request failed)

[^1]: https://github.com/alphagov/notifications-api/pull/3493#discussion_r837363717
This commit is contained in:
Ben Thorner
2022-03-29 14:18:00 +01:00
parent 8432be4fc1
commit 7d92a0869a
7 changed files with 34 additions and 87 deletions

View File

@@ -12,7 +12,7 @@ class SmsClientResponseException(ClientException):
self.message = message
def __str__(self):
return "Message {}".format(self.message)
return f"SMS client error ({self.message})"
class SmsClient(Client):