Improve search error messages

When a more specific error message is available from the search backend,
show the user that instead of a blanket "There was an error, try
searching again."

In github.com/edx/edx-search, we're proposing removing quotes from the
list of reserved characters in Elastic search terms. This enables
searching for exact phrases, but also introduces the possibility of
malformed queries. In those cases, it would be nice to give the user a
hint that they need to change their query, instead of simply trying the
same one again.
This commit is contained in:
John Hensley
2018-01-28 09:08:23 -05:00
committed by Kshitij Sobti
parent 58b9cb4938
commit 1bb7db9925
6 changed files with 16 additions and 7 deletions

View File

@@ -72,7 +72,7 @@
});
dispatcher.listenTo(search, 'error', function() {
form.showErrorMessage();
form.showErrorMessage(search);
form.hideLoadingIndicator();
});

View File

@@ -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');
}
},

View File

@@ -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.'));
}
}
});

View File

@@ -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,

View File

@@ -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();
},

View File

@@ -1 +1 @@
<%- gettext("There was an error, try searching again.") %>
<% if (errorMessage) { %><%- errorMessage %><%} else {%><%- gettext("There was an error, try searching again.") %><% } %>