mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Merge pull request #888 from alphagov/throw-exception-on-long-running-client-call
Throw exception on long running client call
This commit is contained in:
@@ -55,7 +55,8 @@ def make_request(notification_type, provider, data, headers):
|
||||
"POST",
|
||||
api_call,
|
||||
headers=headers,
|
||||
data=data
|
||||
data=data,
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
except RequestException as e:
|
||||
|
||||
@@ -42,8 +42,10 @@ def get_firetext_responses(status):
|
||||
|
||||
class FiretextClientResponseException(SmsClientResponseException):
|
||||
def __init__(self, response, exception):
|
||||
self.status_code = response.status_code
|
||||
self.text = response.text
|
||||
status_code = response.status_code if response is not None else 504
|
||||
text = response.text if response is not None else "Gateway Time-out"
|
||||
self.status_code = status_code
|
||||
self.text = text
|
||||
self.exception = exception
|
||||
|
||||
def __str__(self):
|
||||
@@ -68,11 +70,13 @@ class FiretextClient(SmsClient):
|
||||
return self.name
|
||||
|
||||
def record_outcome(self, success, response):
|
||||
status_code = response.status_code if response else 503
|
||||
|
||||
log_message = "API {} request {} on {} response status_code {}".format(
|
||||
"POST",
|
||||
"succeeded" if success else "failed",
|
||||
self.url,
|
||||
response.status_code
|
||||
status_code
|
||||
)
|
||||
|
||||
if success:
|
||||
@@ -97,7 +101,8 @@ class FiretextClient(SmsClient):
|
||||
response = request(
|
||||
"POST",
|
||||
self.url,
|
||||
data=data
|
||||
data=data,
|
||||
timeout=60
|
||||
)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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)
|
||||
|
||||
@@ -45,8 +44,11 @@ def get_mmg_responses(status):
|
||||
|
||||
class MMGClientResponseException(SmsClientResponseException):
|
||||
def __init__(self, response, exception):
|
||||
self.status_code = response.status_code
|
||||
self.text = response.text
|
||||
status_code = response.status_code if response is not None else 504
|
||||
text = response.text if response is not None else "Gateway Time-out"
|
||||
|
||||
self.status_code = status_code
|
||||
self.text = text
|
||||
self.exception = exception
|
||||
|
||||
def __str__(self):
|
||||
@@ -68,11 +70,12 @@ class MMGClient(SmsClient):
|
||||
self.mmg_url = current_app.config.get('MMG_URL')
|
||||
|
||||
def record_outcome(self, success, response):
|
||||
status_code = response.status_code if response else 503
|
||||
log_message = "API {} request {} on {} response status_code {}".format(
|
||||
"POST",
|
||||
"succeeded" if success else "failed",
|
||||
self.mmg_url,
|
||||
response.status_code
|
||||
status_code
|
||||
)
|
||||
|
||||
if success:
|
||||
@@ -104,7 +107,8 @@ class MMGClient(SmsClient):
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Basic {}'.format(self.api_key)
|
||||
}
|
||||
},
|
||||
timeout=60
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user