luci-app-attendedsysupgrade: add timeout and catch

If the upgrade server API does not respond, show an error message.
Fix #5222

While at it, minimal code linting

Signed-off-by: Paul Spooren <mail@aparcar.org>
This commit is contained in:
Paul Spooren 2021-08-09 08:45:58 -10:00
parent 96ef7beb66
commit ff24b78c80

View file

@ -228,7 +228,9 @@ function check_sysupgrade(server_url, current_version, target, board_name, packa
var advanced_mode = uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0; var advanced_mode = uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0;
var candidates = []; var candidates = [];
fetch(server_url + "/api/latest") request.get(server_url + "/api/latest", {
timeout: 8000
})
.then(response => response.json()) .then(response => response.json())
.then(response => { .then(response => {
if (current_version == "SNAPSHOT") { if (current_version == "SNAPSHOT") {
@ -320,6 +322,20 @@ function check_sysupgrade(server_url, current_version, target, board_name, packa
]) ])
]); ]);
} }
})
.catch(error => {
ui.showModal(_('Error connecting to upgrade server'), [
E('p', {}, _('Could not reach API at "%s". Please try again later.'.format(server_url))),
E('pre', {}, error),
E('div', {
'class': 'right'
}, [
E('div', {
'class': 'btn',
'click': ui.hideModal
}, _('Close'))
])
]);
}); });
} }