mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 10:42:41 -05:00
still return RECEIVED even if we couldn't find a matching service
mmg don't need to retry that message or anything. just log it.
This commit is contained in:
@@ -3,6 +3,7 @@ from urllib.parse import unquote
|
|||||||
from flask import Blueprint, current_app, request
|
from flask import Blueprint, current_app, request
|
||||||
from notifications_utils.recipients import normalise_phone_number
|
from notifications_utils.recipients import normalise_phone_number
|
||||||
|
|
||||||
|
from app import statsd_client
|
||||||
from app.dao.services_dao import dao_fetch_services_by_sms_sender
|
from app.dao.services_dao import dao_fetch_services_by_sms_sender
|
||||||
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
||||||
from app.models import InboundSms
|
from app.models import InboundSms
|
||||||
@@ -30,11 +31,15 @@ def receive_mmg_sms():
|
|||||||
potential_services = dao_fetch_services_by_sms_sender(post_data['Number'])
|
potential_services = dao_fetch_services_by_sms_sender(post_data['Number'])
|
||||||
|
|
||||||
if len(potential_services) != 1:
|
if len(potential_services) != 1:
|
||||||
current_app.logger.error('')
|
current_app.logger.error('Inbound number "{}" not associated with exactly one service'.format(
|
||||||
raise InvalidRequest(
|
post_data['Number']
|
||||||
'Inbound number "{}" not associated with exactly one service'.format(post_data['Number']),
|
))
|
||||||
status_code=400
|
statsd_client.incr('inbound.mmg.failed')
|
||||||
)
|
# since this is an issue with our service <-> number mapping, we should still tell MMG that we received
|
||||||
|
# succesfully
|
||||||
|
return 'RECEIVED', 200
|
||||||
|
|
||||||
|
statsd_client.incr('inbound.mmg.succesful')
|
||||||
|
|
||||||
service = potential_services[0]
|
service = potential_services[0]
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from app.notifications.receive_notifications import (
|
|||||||
create_inbound_sms_object
|
create_inbound_sms_object
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from app.models import InboundSms
|
||||||
from tests.app.db import create_service
|
from tests.app.db import create_service
|
||||||
|
|
||||||
|
|
||||||
@@ -76,8 +77,7 @@ def test_receive_notification_error_if_not_single_matching_service(client, notif
|
|||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=[('Content-Type', 'application/json')])
|
headers=[('Content-Type', 'application/json')])
|
||||||
|
|
||||||
assert response.status_code == 400
|
# we still return 'RECEIVED' to MMG
|
||||||
assert json.loads(response.get_data(as_text=True)) == {
|
assert response.status_code == 200
|
||||||
'result': 'error',
|
assert response.get_data(as_text=True) == 'RECEIVED'
|
||||||
'message': 'Inbound number "{}" not associated with exactly one service'.format(notify_number)
|
assert InboundSms.query.count() == 0
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user