Check failure code on failure only.

We should check error code on failure only, because if we get an
error code on pending code, we should still set the notification
to pending status.
This commit is contained in:
Pea Tyczynska
2020-04-21 13:30:42 +01:00
parent 750a573afc
commit 9782cbc5b5
3 changed files with 21 additions and 4 deletions

View File

@@ -91,16 +91,19 @@ def dao_create_notification(notification):
def _decide_permanent_temporary_failure(status, notification, code=None):
# Firetext will send pending, then send either succes or fail.
# If we go from pending to failure we need to set failure type as temporary-failure,
# unless we get a detailed code from firetext. Then we should use that code to set status instead.
if code and code != '000':
# If we get failure status from Firetext, we want to know if this is temporary or permanent failure.
# So we check the failure code to learn that.
# If there is no failure code, or we do not recognise the failure code, we do the following:
# if notifitcation goes form status pending to status failure, we mark it as temporary failure;
# if notification goes straight to status failure, we mark it as permanent failure.
if status == NOTIFICATION_PERMANENT_FAILURE and code not in [None, '000']:
try:
status, reason = get_message_status_and_reason_from_firetext_code(code)
current_app.logger.info(f'Updating notification id {notification.id} to status {status}, reason: {reason}')
return status
except KeyError:
current_app.logger.warning(f'Failure code {code} from Firetext not recognised')
# fallback option:
if notification.status == NOTIFICATION_PENDING and status == NOTIFICATION_PERMANENT_FAILURE:
status = NOTIFICATION_TEMPORARY_FAILURE
return status