mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
We are not handling the case of an unknown status code sent by the SMS provider. This PR attempts to fix that.
- If the SMS client sends a status code that we do not recognize raise a ClientException and set the notification status to technical-failure - Simplified the code in process_client_response, using a simple map.
This commit is contained in:
@@ -5,7 +5,6 @@ from monotonic import monotonic
|
||||
from requests import request, RequestException
|
||||
|
||||
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
||||
from app.clients import STATISTICS_DELIVERED, STATISTICS_FAILURE
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -15,24 +14,9 @@ logger = logging.getLogger(__name__)
|
||||
# the notification status to temporary-failure rather than permanent failure.
|
||||
# See the code in the notification_dao.update_notifications_status_by_id
|
||||
firetext_responses = {
|
||||
'0': {
|
||||
"message": 'Delivered',
|
||||
"notification_statistics_status": STATISTICS_DELIVERED,
|
||||
"success": True,
|
||||
"notification_status": 'delivered'
|
||||
},
|
||||
'1': {
|
||||
"message": 'Declined',
|
||||
"success": False,
|
||||
"notification_statistics_status": STATISTICS_FAILURE,
|
||||
"notification_status": 'permanent-failure'
|
||||
},
|
||||
'2': {
|
||||
"message": 'Undelivered (Pending with Network)',
|
||||
"success": True,
|
||||
"notification_statistics_status": None,
|
||||
"notification_status": 'pending'
|
||||
}
|
||||
'0': 'delivered',
|
||||
'1': 'permanent-failure',
|
||||
'2': 'pending'
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +1,18 @@
|
||||
import json
|
||||
from monotonic import monotonic
|
||||
from requests import (request, RequestException)
|
||||
from app.clients import (STATISTICS_DELIVERED, STATISTICS_FAILURE)
|
||||
from app.clients.sms import (SmsClient, SmsClientResponseException)
|
||||
|
||||
mmg_response_map = {
|
||||
'2': {
|
||||
"message": ' Permanent failure',
|
||||
"notification_statistics_status": STATISTICS_FAILURE,
|
||||
"success": False,
|
||||
"notification_status": 'permanent-failure'
|
||||
},
|
||||
'3': {
|
||||
"message": 'Delivered',
|
||||
"notification_statistics_status": STATISTICS_DELIVERED,
|
||||
"success": True,
|
||||
"notification_status": 'delivered'
|
||||
},
|
||||
'4': {
|
||||
"message": ' Temporary failure',
|
||||
"notification_statistics_status": STATISTICS_FAILURE,
|
||||
"success": False,
|
||||
"notification_status": 'temporary-failure'
|
||||
},
|
||||
'5': {
|
||||
"message": 'Permanent failure',
|
||||
"notification_statistics_status": STATISTICS_FAILURE,
|
||||
"success": False,
|
||||
"notification_status": 'permanent-failure'
|
||||
},
|
||||
'default': {
|
||||
"message": 'Declined',
|
||||
"success": False,
|
||||
"notification_statistics_status": STATISTICS_FAILURE,
|
||||
"notification_status": 'failed'
|
||||
}
|
||||
'2': 'permanent-failure',
|
||||
'3': 'delivered',
|
||||
'4': 'temporary-failure',
|
||||
'5': 'permanent-failure'
|
||||
}
|
||||
|
||||
|
||||
def get_mmg_responses(status):
|
||||
return mmg_response_map.get(status, mmg_response_map.get('default'))
|
||||
return mmg_response_map[status]
|
||||
|
||||
|
||||
class MMGClientResponseException(SmsClientResponseException):
|
||||
|
||||
Reference in New Issue
Block a user