[fix] Prevent data loss on form errors. Add some comments too.

This commit is contained in:
opi 2016-03-16 17:51:51 +01:00
parent 985aacdd00
commit 670d6768a2

View file

@ -96,6 +96,8 @@
callback(data); callback(data);
}) })
.fail(function(xhr) { .fail(function(xhr) {
// Postinstall is a custom case, we have to wait that
// operation is done before doing anything
if (uri === '/postinstall') { if (uri === '/postinstall') {
if (installing) { if (installing) {
interval = window.location.hostname === args.domain ? 20000 : 5000; interval = window.location.hostname === args.domain ? 20000 : 5000;
@ -111,27 +113,42 @@
} else { } else {
c.flash('fail', y18n.t('error_occured')); c.flash('fail', y18n.t('error_occured'));
} }
} else if (xhr.status == 200) { }
// Regular errors
else {
if (xhr.status == 200) {
// Fail with 200, WTF // Fail with 200, WTF
callback({}); callback({});
} else if (xhr.status == 401) { }
// Unauthorized or wrong password
else if (xhr.status == 401) {
if (uri === '/login') { if (uri === '/login') {
c.flash('fail', y18n.t('wrong_password')); c.flash('fail', y18n.t('wrong_password'));
} else { } else {
c.flash('fail', y18n.t('unauthorized')); c.flash('fail', y18n.t('unauthorized'));
c.redirect('#/login'); c.redirect('#/login');
} }
} else if (xhr.status == 502) { }
// 502 Bad gateway means API is down
else if (xhr.status == 502) {
c.flash('fail', y18n.t('api_not_responding')); c.flash('fail', y18n.t('api_not_responding'));
} else if (typeof xhr.responseText !== 'undefined') { }
// More verbose error messages first
else if (typeof xhr.responseText !== 'undefined') {
c.flash('fail', xhr.responseText); c.flash('fail', xhr.responseText);
} else { }
// Return HTTP error code at least
else {
var errorMessage = xhr.status+' '+xhr.statusText; var errorMessage = xhr.status+' '+xhr.statusText;
c.flash('fail', y18n.t('error_server_unexpected', [errorMessage])); c.flash('fail', y18n.t('error_server_unexpected', [errorMessage]));
} }
if (uri !== '/postinstall') {
// Remove loader if any
$('div.loader').remove();
// Force scrollTop on page load
$('html, body').scrollTop(0);
store.clear('slide'); store.clear('slide');
c.redirect(store.get('path-1'));
} }
}); });
}; };