mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[fix] Prevent data loss on form errors. Add some comments too.
This commit is contained in:
parent
985aacdd00
commit
670d6768a2
1 changed files with 36 additions and 19 deletions
|
@ -96,6 +96,8 @@
|
|||
callback(data);
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
// Postinstall is a custom case, we have to wait that
|
||||
// operation is done before doing anything
|
||||
if (uri === '/postinstall') {
|
||||
if (installing) {
|
||||
interval = window.location.hostname === args.domain ? 20000 : 5000;
|
||||
|
@ -111,27 +113,42 @@
|
|||
} else {
|
||||
c.flash('fail', y18n.t('error_occured'));
|
||||
}
|
||||
} else if (xhr.status == 200) {
|
||||
// Fail with 200, WTF
|
||||
callback({});
|
||||
} else if (xhr.status == 401) {
|
||||
if (uri === '/login') {
|
||||
c.flash('fail', y18n.t('wrong_password'));
|
||||
} else {
|
||||
c.flash('fail', y18n.t('unauthorized'));
|
||||
c.redirect('#/login');
|
||||
}
|
||||
} else if (xhr.status == 502) {
|
||||
c.flash('fail', y18n.t('api_not_responding'));
|
||||
} else if (typeof xhr.responseText !== 'undefined') {
|
||||
c.flash('fail', xhr.responseText);
|
||||
} else {
|
||||
var errorMessage = xhr.status+' '+xhr.statusText;
|
||||
c.flash('fail', y18n.t('error_server_unexpected', [errorMessage]));
|
||||
}
|
||||
if (uri !== '/postinstall') {
|
||||
// Regular errors
|
||||
else {
|
||||
if (xhr.status == 200) {
|
||||
// Fail with 200, WTF
|
||||
callback({});
|
||||
}
|
||||
// Unauthorized or wrong password
|
||||
else if (xhr.status == 401) {
|
||||
if (uri === '/login') {
|
||||
c.flash('fail', y18n.t('wrong_password'));
|
||||
} else {
|
||||
c.flash('fail', y18n.t('unauthorized'));
|
||||
c.redirect('#/login');
|
||||
}
|
||||
}
|
||||
// 502 Bad gateway means API is down
|
||||
else if (xhr.status == 502) {
|
||||
c.flash('fail', y18n.t('api_not_responding'));
|
||||
}
|
||||
// More verbose error messages first
|
||||
else if (typeof xhr.responseText !== 'undefined') {
|
||||
c.flash('fail', xhr.responseText);
|
||||
}
|
||||
// Return HTTP error code at least
|
||||
else {
|
||||
var errorMessage = xhr.status+' '+xhr.statusText;
|
||||
c.flash('fail', y18n.t('error_server_unexpected', [errorMessage]));
|
||||
}
|
||||
|
||||
// Remove loader if any
|
||||
$('div.loader').remove();
|
||||
|
||||
// Force scrollTop on page load
|
||||
$('html, body').scrollTop(0);
|
||||
store.clear('slide');
|
||||
c.redirect(store.get('path-1'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue