mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Removed the HTTP error and arguments from notification_ses_callback.py
In preparation for moving the SNS notification to an SES queue remove the HTTP errors codes and arguments as the method will now be run by a celery task. Also made the callback http method return more generic codes as this will be removed in the longer term. - Removed errors and arguments returned from process_ses_response - Updated tests
This commit is contained in:
@@ -27,11 +27,12 @@ register_errors(ses_callback_blueprint)
|
||||
|
||||
@ses_callback_blueprint.route('/notifications/email/ses', methods=['POST'])
|
||||
def sns_callback_handler():
|
||||
errors, status, kwargs = process_ses_response(json.loads(request.data))
|
||||
errors = process_ses_response(json.loads(request.data))
|
||||
if errors:
|
||||
raise InvalidRequest(errors, status)
|
||||
current_app.logger.error(errors)
|
||||
raise InvalidRequest(errors, 400)
|
||||
|
||||
return jsonify(**kwargs), status
|
||||
return 200
|
||||
|
||||
|
||||
def process_ses_response(ses_request):
|
||||
@@ -44,12 +45,12 @@ def process_ses_response(ses_request):
|
||||
|
||||
errors = validate_callback_data(data=ses_request, fields=['Message'], client_name=client_name)
|
||||
if errors:
|
||||
return errors, 400, {}
|
||||
return errors
|
||||
|
||||
ses_message = json.loads(ses_request['Message'])
|
||||
errors = validate_callback_data(data=ses_message, fields=['notificationType'], client_name=client_name)
|
||||
if errors:
|
||||
return errors, 400, {}
|
||||
return errors
|
||||
|
||||
notification_type = ses_message['notificationType']
|
||||
if notification_type == 'Bounce':
|
||||
@@ -61,7 +62,7 @@ def process_ses_response(ses_request):
|
||||
aws_response_dict = get_aws_responses(notification_type)
|
||||
except KeyError:
|
||||
error = "{} callback failed: status {} not found".format(client_name, notification_type)
|
||||
return error, 400, {}
|
||||
return error
|
||||
|
||||
notification_status = aws_response_dict['notification_status']
|
||||
|
||||
@@ -74,7 +75,7 @@ def process_ses_response(ses_request):
|
||||
if not notification:
|
||||
error = "SES callback failed: notification either not found or already updated " \
|
||||
"from sending. Status {} for notification reference {}".format(notification_status, reference)
|
||||
return error, 404, {}
|
||||
return error
|
||||
|
||||
if not aws_response_dict['success']:
|
||||
current_app.logger.info(
|
||||
@@ -99,12 +100,12 @@ def process_ses_response(ses_request):
|
||||
|
||||
create_outcome_notification_statistic_tasks(notification)
|
||||
|
||||
return [], 200, {'result': "success", 'message': "SES callback succeeded"}
|
||||
return
|
||||
|
||||
except KeyError:
|
||||
error = "SES callback failed: messageId missing"
|
||||
return error, 400, {}
|
||||
return error
|
||||
|
||||
except ValueError:
|
||||
error = "{} callback failed: invalid json".format(client_name)
|
||||
return error, 400, {}
|
||||
return error
|
||||
|
||||
Reference in New Issue
Block a user