From cc8f36a94f3fb784c4f93c04ac59555a5414bbcf Mon Sep 17 00:00:00 2001 From: John Hensley Date: Sun, 28 Jan 2018 18:27:17 -0500 Subject: [PATCH] Make response.responseJSON check still more robust --- .../js/collections/search_collection.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/openedx/features/course_search/static/course_search/js/collections/search_collection.js b/openedx/features/course_search/static/course_search/js/collections/search_collection.js index 085ef93a60..2f1471fac0 100644 --- a/openedx/features/course_search/static/course_search/js/collections/search_collection.js +++ b/openedx/features/course_search/static/course_search/js/collections/search_collection.js @@ -40,11 +40,16 @@ }, type: 'POST', success: function(self) { - self.errorMessage = ''; + self.errorMessage = ''; // eslint-disable-line no-param-reassign self.trigger('search'); }, error: function(self, response) { - self.errorMessage = response.responseJSON ? response.responseJSON.error: ''; + if (response.responseJSON && response.responseJSON.error) { + self.errorMessage = response.responseJSON.error || ''; // eslint-disable-line no-param-reassign + } else { + self.errorMessage = ''; // eslint-disable-line no-param-reassign + } + self.trigger('error'); } }); @@ -62,12 +67,17 @@ }, type: 'POST', success: function(self) { - self.errorMessage = ''; + self.errorMessage = ''; // eslint-disable-line no-param-reassign self.page += 1; // eslint-disable-line no-param-reassign self.trigger('next'); }, error: function(self, response) { - self.errorMessage = response.responseJSON ? response.responseJSON.error: ''; + if (response.responseJSON && response.responseJSON.error) { + self.errorMessage = response.responseJSON.error || ''; // eslint-disable-line no-param-reassign + } else { + self.errorMessage = ''; // eslint-disable-line no-param-reassign + } + self.trigger('error'); }, add: true,