diff --git a/lms/static/js/discovery/discovery_factory.js b/lms/static/js/discovery/discovery_factory.js index 514b88aefd..91ce584766 100644 --- a/lms/static/js/discovery/discovery_factory.js +++ b/lms/static/js/discovery/discovery_factory.js @@ -72,7 +72,7 @@ }); dispatcher.listenTo(search, 'error', function() { - form.showErrorMessage(); + form.showErrorMessage(search); form.hideLoadingIndicator(); }); diff --git a/lms/static/js/discovery/models/search_state.js b/lms/static/js/discovery/models/search_state.js index 2bb270f4a7..cd37f938ea 100644 --- a/lms/static/js/discovery/models/search_state.js +++ b/lms/static/js/discovery/models/search_state.js @@ -72,10 +72,12 @@ reset: function() { this.discovery.reset(); this.page = 0; + this.errorMessage = ''; }, onError: function(collection, response, options) { if (response.statusText !== 'abort') { + this.errorMessage = response.responseJSON.error; this.trigger('error'); } }, diff --git a/lms/static/js/discovery/views/search_form.js b/lms/static/js/discovery/views/search_form.js index a9b17672a9..fbbb598980 100644 --- a/lms/static/js/discovery/views/search_form.js +++ b/lms/static/js/discovery/views/search_form.js @@ -60,8 +60,12 @@ this.clearSearch(); }, - showErrorMessage: function() { - this.$message.html(gettext('There was an error, try searching again.')); + showErrorMessage: function(search) { + if (search && search.errorMessage) { + this.$message.html(gettext(search.errorMessage)); + } else { + this.$message.html(gettext('There was an error, try searching again.')); + } } }); 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 867dcb07eb..29dafc88e3 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,9 +40,11 @@ }, type: 'POST', success: function(self) { + self.errorMessage = ''; self.trigger('search'); }, - error: function(self) { + error: function(self, response) { + self.errorMessage = response.responseJSON.error; self.trigger('error'); } }); @@ -63,7 +65,8 @@ self.page += 1; // eslint-disable-line no-param-reassign self.trigger('next'); }, - error: function(self) { + error: function(self, response) { + self.errorMessage = response.responseJSON.error; self.trigger('error'); }, add: true, diff --git a/openedx/features/course_search/static/course_search/js/views/search_results_view.js b/openedx/features/course_search/static/course_search/js/views/search_results_view.js index 99d4f1a7e4..5d7bf188b1 100644 --- a/openedx/features/course_search/static/course_search/js/views/search_results_view.js +++ b/openedx/features/course_search/static/course_search/js/views/search_results_view.js @@ -93,7 +93,7 @@ }, showErrorMessage: function() { - HtmlUtils.setHtml(this.$el, HtmlUtils.template(this.errorTemplate)()); + HtmlUtils.setHtml(this.$el, HtmlUtils.template(this.errorTemplate)({errorMessage: this.collection.errorMessage})); this.showResults(); }, diff --git a/openedx/features/course_search/static/course_search/templates/search_error.underscore b/openedx/features/course_search/static/course_search/templates/search_error.underscore index 35990e2783..4d4dcbe497 100644 --- a/openedx/features/course_search/static/course_search/templates/search_error.underscore +++ b/openedx/features/course_search/static/course_search/templates/search_error.underscore @@ -1 +1 @@ -<%- gettext("There was an error, try searching again.") %> +<% if (errorMessage) { %><%- errorMessage %><%} else {%><%- gettext("There was an error, try searching again.") %><% } %>