Better error handling

This commit is contained in:
Benjamin Drieu 2021-11-18 23:16:59 +01:00 committed by Benjamin Drieu
parent 49f4cbebb4
commit 25a3f7a6e8
4 changed files with 42 additions and 24 deletions

View File

@ -245,6 +245,12 @@ class Indicator extends PanelMenu.Button {
this._box.remove_all_children();
if ( serverLogic.error )
{
this._box.add_child ( new St.Label ( { style_class: 'monito-network-error', text: serverLogic.error } ) );
return;
}
let headerBox = new St.BoxLayout({
style_class: 'monito-service-line',
hover: true,

View File

@ -69,17 +69,21 @@ class Icinga {
{
log ( '>>> error: ' + message.reason_phrase );
Main.notify ( 'Monito: ' + name, message.reason_phrase );
return;
this.status = null;
this.error = message.reason_phrase;
}
else
{
let json = JSON.parse(message.response_body.data);
this.status = json.status;
this.error = null;
}
extension.refreshUI ( this );
}
)
);
return true;
return this.status != null;
}
catch (e) {
Main.notify(_('Zbeu!'));

View File

@ -74,21 +74,22 @@ class Icinga2 {
handleMessage ( _httpSession, message )
{
this.status = { };
this.status.service_status = [ ];
if ( message.status_code != Soup.Status.OK )
{
log ( '>>> error: ' + message.reason_phrase );
Main.notifyError ( 'Monito: ' + this.name,
'URL: ' + this.urlcgi + "\n" +
message.status_code + ': ' + message.reason_phrase );
return;
this.error = message.reason_phrase;
}
else
{
let json = JSON.parse(message.response_body.data);
let _statuses = [ 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ];
this.status = { };
this.status.service_status = [ ];
for ( var entry of json )
{
this.status.service_status.push ( {
@ -100,9 +101,11 @@ class Icinga2 {
last_check: new Date ( parseInt(entry.service_last_state_change) * 1000 ) . toString(),
} );
}
this.error = null;
}
this.extension.refreshUI ( this );
return true;
return this.status != { };
}
}

View File

@ -84,6 +84,11 @@
margin: 2px;
}
.monito-network-error {
font-size: 150%;
font-weight: bold;
}
.monito-button-icon {
padding: 0px;
margin: 0px;