server_events: Extract functions for managing connection errors.

This cuts a bit of code duplication.
This commit is contained in:
Tim Abbott 2018-11-29 12:31:08 -08:00
parent 01927fb470
commit 83b127cec1
1 changed files with 14 additions and 8 deletions

View File

@ -142,6 +142,16 @@ function get_events_success(events) {
});
}
function show_ui_connection_error() {
ui_report.show_error($("#connection-error"));
$("#connection-error").addClass('get-events-error');
}
function hide_ui_connection_error() {
ui_report.hide_error($("#connection-error"));
$("#connection-error").removeClass('get-events-error');
}
function get_events(options) {
options = _.extend({dont_block: false}, options);
@ -183,8 +193,7 @@ function get_events(options) {
try {
get_events_xhr = undefined;
get_events_failures = 0;
ui_report.hide_error($("#connection-error"));
$("#connection-error").removeClass('get-events-error');
hide_ui_connection_error();
get_events_success(data.events);
} catch (ex) {
@ -215,18 +224,15 @@ function get_events(options) {
} else if (error_type === 'timeout') {
// Retry indefinitely on timeout.
get_events_failures = 0;
ui_report.hide_error($("#connection-error"));
$("#connection-error").removeClass('get-events-error');
hide_ui_connection_error();
} else {
get_events_failures += 1;
}
if (get_events_failures >= 5) {
ui_report.show_error($("#connection-error"));
$("#connection-error").addClass('get-events-error');
show_ui_connection_error();
} else {
ui_report.hide_error($("#connection-error"));
$("#connection-error").removeClass('get-events-error');
hide_ui_connection_error();
}
} catch (ex) {
blueslip.error('Failed to handle get_events error\n' +