Handle Exception in getting cookies from Sailthru
In order to send email, cookies are required from Sailthru, ocassionally, celery task fails possibly because of request timeout that ultimately fails login.To avoid it,generic exception handler is added so that login will not fail in future. LEARNER-3465
This commit is contained in:
@@ -97,6 +97,9 @@ def add_email_marketing_cookies(sender, response=None, user=None,
|
||||
except SailthruClientError as exc:
|
||||
log.error("Exception attempting to obtain cookie from Sailthru: %s", unicode(exc))
|
||||
return response
|
||||
except Exception:
|
||||
log.error("Exception Connecting to celery task for %s", user.email)
|
||||
return response
|
||||
|
||||
if not cookie:
|
||||
log.error("No cookie returned attempting to obtain cookie from Sailthru for %s", user.email)
|
||||
|
||||
@@ -195,6 +195,21 @@ class EmailMarketingTests(TestCase):
|
||||
self.assertEquals(userparms['vars']['activated'], 1)
|
||||
self.assertEquals(userparms['lists']['new list'], 1)
|
||||
|
||||
@patch('lms.djangoapps.email_marketing.signals.get_email_cookies_via_sailthru.delay')
|
||||
def test_drop_cookie_task_error(self, mock_email_cookies):
|
||||
"""
|
||||
Tests that task error is handled
|
||||
"""
|
||||
mock_email_cookies.return_value = {}
|
||||
mock_email_cookies.get.side_effect = Exception
|
||||
with LogCapture(LOGGER_NAME, level=logging.INFO) as logger:
|
||||
add_email_marketing_cookies(None, response=None, user=self.user)
|
||||
logger.check((
|
||||
LOGGER_NAME, 'ERROR', 'Exception Connecting to celery task for {}'.format(
|
||||
self.user.email
|
||||
)
|
||||
))
|
||||
|
||||
@patch('email_marketing.tasks.log.error')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_post')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_get')
|
||||
|
||||
Reference in New Issue
Block a user