|
1 | 1 | /**
|
2 | 2 | * Send the search term to the backend, process and display the results or show errors if there are any.
|
3 | 3 | *
|
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 |
7 | 8 | * @returns {Promise<{}>}
|
8 | 9 | */
|
9 | 10 | async function _search(url, search_term, pinned = [], focus_command_input = false) {
|
@@ -93,24 +94,31 @@ servershell.submit_search = function(focus_command_input = false) {
|
93 | 94 |
|
94 | 95 | _search(url, servershell.term, touched_objects, focus_command_input)
|
95 | 96 | .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 | + } |
104 | 104 | })
|
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 | + } |
110 | 115 | })
|
111 | 116 | .finally(function() {
|
112 | 117 | spinner.disable('search');
|
113 | 118 |
|
| 119 | + // We will use this on other components to react on changes ... |
| 120 | + $(document).trigger('servershell_search_finished'); |
| 121 | + |
114 | 122 | // Reset running ajax call variable
|
115 | 123 | servershell._ajax = null;
|
116 | 124 | })
|
|
0 commit comments