mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Make code a bit more defensive and add som logging
This commit is contained in:
@@ -32,13 +32,14 @@ def process_ses_response():
|
||||
try:
|
||||
ses_request = json.loads(request.data)
|
||||
|
||||
if 'Type' in ses_request and ses_request['Type'] == 'SubscriptionConfirmation':
|
||||
if ses_request.get('Type') == 'SubscriptionConfirmation':
|
||||
current_app.logger.info("SNS subscription confirmation url: {}".format(ses_request['SubscribeURL']))
|
||||
subscribed_topic = confirm_subscription(ses_request)
|
||||
current_app.logger.info("Automatically subscribed to topic: {}".format(subscribed_topic))
|
||||
return jsonify(
|
||||
result="success", message="SES callback succeeded"
|
||||
), 200
|
||||
if subscribed_topic:
|
||||
current_app.logger.info("Automatically subscribed to topic: {}".format(subscribed_topic))
|
||||
return jsonify(
|
||||
result="success", message="SES callback succeeded"
|
||||
), 200
|
||||
|
||||
errors = validate_callback_data(data=ses_request, fields=['Message'], client_name=client_name)
|
||||
if errors:
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
from flask import current_app
|
||||
import requests
|
||||
|
||||
|
||||
def confirm_subscription(confirmation_request):
|
||||
url = confirmation_request['SubscribeURL']
|
||||
url = confirmation_request.get('SubscribeURL')
|
||||
if not url:
|
||||
current_app.logger.warning("SubscribeURL does not exist or empty")
|
||||
return
|
||||
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except Exception as e:
|
||||
current_app.logger.warning("Response: {}".format(response.text))
|
||||
raise e
|
||||
|
||||
return confirmation_request['TopicArn']
|
||||
|
||||
Reference in New Issue
Block a user