Skip to content

Commit

Permalink
remove unused error hndler
Browse files Browse the repository at this point in the history
  • Loading branch information
hanars committed Mar 12, 2024
1 parent c87ea28 commit 4d15bac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
11 changes: 2 additions & 9 deletions matchmaker/views/external_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,15 @@ def mme_match_proxy(request, originating_node_name):
patient_data=query_patient_data, origin_request_host=originating_node_name,
)

try:
_generate_notification_for_incoming_match(results, incoming_query, originating_node_name, query_patient_data)
except Exception as e:
logger.error('Unable to create notification for incoming MME match request for {} matches{}: {}'.format(
len(results),
' ({})'.format(', '.join(sorted([result.get('patient', {}).get('id') for result in results]))) if results else '',
str(e)),
)
_safe_generate_notification_for_incoming_match(results, incoming_query, originating_node_name, query_patient_data)

return create_json_response({
'results': sorted(results, key=lambda result: result['score']['patient'], reverse=True),
'_disclaimer': MME_DISCLAIMER,
})


def _generate_notification_for_incoming_match(results, incoming_query, incoming_request_node, incoming_patient):
def _safe_generate_notification_for_incoming_match(results, incoming_query, incoming_request_node, incoming_patient):
"""
Generate a SLACK notifcation to say that a VALID match request came in and the following
results were sent back. If Slack is not supported, a message is not sent, but details persisted.
Expand Down
13 changes: 7 additions & 6 deletions matchmaker/views/external_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ def test_mme_match_proxy_phenotype_only(self, mock_post_to_slack, mock_email):
mock.call().send(),
])

@mock.patch('matchmaker.views.external_api.logger')
@mock.patch('seqr.utils.communication_utils.logger')
@mock.patch('matchmaker.views.external_api.EmailMessage')
@mock.patch('matchmaker.views.external_api.safe_post_to_slack')
@mock.patch('seqr.utils.communication_utils._post_to_slack')
def test_mme_match_proxy_no_results(self, mock_post_to_slack, mock_email, mock_logger):
url = '/api/matchmaker/v1/match'
request_body = {
Expand All @@ -424,11 +424,12 @@ def test_mme_match_proxy_no_results(self, mock_post_to_slack, mock_email, mock_l
self.assertEqual(incoming_query_q.count(), 1)
self.assertIsNone(incoming_query_q.first().patient_id)

mock_post_to_slack.assert_called_with(
'matchmaker_matches',
"""A match request for 12345 came in from Test Institute today.
slack_message = """A match request for 12345 came in from Test Institute today.
The contact information given was: [email protected].
We didn't find any individuals in matchbox that matched that query well, *so no results were sent back*."""
mock_post_to_slack.assert_called_with(
'matchmaker_matches',
slack_message
)
mock_email.assert_not_called()

Expand All @@ -440,6 +441,6 @@ def test_mme_match_proxy_no_results(self, mock_post_to_slack, mock_email, mock_l
self.assertListEqual(response.json()['results'], [])
self.assertEqual(MatchmakerIncomingQuery.objects.filter(institution='Test Institute').count(), 2)
mock_logger.error.assert_called_with(
'Unable to create notification for incoming MME match request for 0 matches: Slack connection error')
f'Slack error: Slack connection error: Original message in channel (matchmaker_matches) - {slack_message}')


0 comments on commit 4d15bac

Please sign in to comment.