mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-25 12:01:38 -05:00
This reduces the code to copy when we add a new provider. I don't think we need to log the URL or status code each time: - The URL is always the same. - A "200" status code is implicit in "success". - Other status codes will be reported as exceptions. Removing these specific elements means "record_outcome" is generic and can be de-duplicated in the base class.
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
from app.clients import Client, ClientException
|
|
|
|
|
|
class SmsClientResponseException(ClientException):
|
|
'''
|
|
Base Exception for SmsClientsResponses
|
|
'''
|
|
|
|
def __init__(self, message):
|
|
self.message = message
|
|
|
|
def __str__(self):
|
|
return "Message {}".format(self.message)
|
|
|
|
|
|
class SmsClient(Client):
|
|
'''
|
|
Base Sms client for sending smss.
|
|
'''
|
|
|
|
def record_outcome(self, success):
|
|
log_message = "Provider request for {} {}".format(
|
|
self.name,
|
|
"succeeded" if success else "failed",
|
|
)
|
|
|
|
if success:
|
|
self.current_app.logger.info(log_message)
|
|
self.statsd_client.incr(f"clients.{self.name}.success")
|
|
else:
|
|
self.statsd_client.incr(f"clients.{self.name}.error")
|
|
self.current_app.logger.warning(log_message)
|
|
|
|
def send_sms(self, *args, **kwargs):
|
|
raise NotImplementedError('TODO Need to implement.')
|
|
|
|
@property
|
|
def name(self):
|
|
raise NotImplementedError('TODO Need to implement.')
|