Skip to content

Commit

Permalink
Hotfix to Return 201 on PUSH Timeout (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-macmillan authored Oct 30, 2023
1 parent 1753ce5 commit 8061a84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/va/vetext/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def send_push_notification(self, mobile_app: str, template_id: str, icn: str, pe
)
self.logger.info("VEText response: %s", response.json() if response.ok else response.status_code)
response.raise_for_status()
except requests.exceptions.ReadTimeout:
# Discussion with VEText: read timeouts are still processed, so are marking this as good
self.logger.warning('ReadTimeout exceptions are still processed, returning 201')
# Logging as error.read_timeout so we can easily track it
self.statsd.incr(f"{self.STATSD_KEY}.error.read_timeout")
except requests.HTTPError as e:
self.logger.exception(e)
self.statsd.incr(f"{self.STATSD_KEY}.error.{e.response.status_code}")
Expand Down
9 changes: 9 additions & 0 deletions tests/app/v2/notifications/test_push_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from app.models import PUSH_TYPE
from app.mobile_app import MobileAppType, DEAFULT_MOBILE_APP_TYPE
from app.va.vetext import VETextClient, VETextBadRequestException, VETextNonRetryableException, VETextRetryableException
import requests
import requests_mock
from tests.app.factories.feature_flag import mock_feature_flag
from tests.app.db import (
create_service,
Expand Down Expand Up @@ -131,6 +133,13 @@ def test_returns_201(self, client, service_with_push_permission, vetext_client):

assert response.status_code == 201

def test_returns_201_after_read_timeout(self, client, service_with_push_permission, vetext_client):
with requests_mock.Mocker() as m:
m.post(f'{client.application.config["VETEXT_URL"]}/mobile/push/send', exc=requests.exceptions.ReadTimeout)
response = post_send_notification(client, service_with_push_permission, 'push', push_request)

assert response.status_code == 201

@pytest.mark.parametrize('payload, personalisation, app', [
(push_request, None, DEAFULT_MOBILE_APP_TYPE.value),
({**push_request, 'personalisation': {'foo': 'bar'},
Expand Down

0 comments on commit 8061a84

Please sign in to comment.