Skip to content

Commit d6c420d

Browse files
authored
Servershell: More graceful error handling (#407)
* Update docs for _search function * More graceful error handling on search errors
1 parent 29b8618 commit d6c420d

File tree

1 file changed

+24
-16
lines changed
  • serveradmin/servershell/static/js/servershell

1 file changed

+24
-16
lines changed

serveradmin/servershell/static/js/servershell/search.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* Send the search term to the backend, process and display the results or show errors if there are any.
33
*
4-
* @param url
5-
* @param search_term
6-
* @param pinned
4+
* @param url Serveradmin servershell query URL (e.g. /servershell/results)
5+
* @param search_term Text based query (e.g. project=foo)
6+
* @param pinned List ob object ids to query besides search_term
7+
* @param focus_command_input Focus on command input when done or not
78
* @returns {Promise<{}>}
89
*/
910
async function _search(url, search_term, pinned = [], focus_command_input = false) {
@@ -93,24 +94,31 @@ servershell.submit_search = function(focus_command_input = false) {
9394

9495
_search(url, servershell.term, touched_objects, focus_command_input)
9596
.then(data => {
96-
servershell.editable_attributes = data.editable_attributes;
97-
servershell.servers = data.servers;
98-
servershell.num_servers = data.num_servers;
99-
servershell.status = data.status;
100-
servershell.understood = data.understood;
101-
102-
// We will use this on other components to react on changes ...
103-
$(document).trigger('servershell_search_finished');
97+
if (data) {
98+
servershell.editable_attributes = data.editable_attributes;
99+
servershell.servers = data.servers;
100+
servershell.num_servers = data.num_servers;
101+
servershell.status = data.status;
102+
servershell.understood = data.understood;
103+
}
104104
})
105-
.catch(function() {
106-
servershell.alert(
107-
'Request to Serveradmin failed!' +
108-
'You could try again or check the browser console for details.',
109-
'danger');
105+
.catch(function(xhr) {
106+
if (xhr.status === 0) {
107+
servershell.alert('Network error while requesting Serveradmin!', 'danger');
108+
}
109+
else if (xhr.status in [500, 502, 503, 504]) {
110+
servershell.alert(`HTTP error: ${xhr.status}! If retry does not help let us know.`)
111+
}
112+
else if (xhr.status === 401) {
113+
servershell.alert('Session expired. You need to login again!');
114+
}
110115
})
111116
.finally(function() {
112117
spinner.disable('search');
113118

119+
// We will use this on other components to react on changes ...
120+
$(document).trigger('servershell_search_finished');
121+
114122
// Reset running ajax call variable
115123
servershell._ajax = null;
116124
})

0 commit comments

Comments
 (0)