mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[fix] Reorder and catch proper response from API failed calls
This commit is contained in:
parent
87a7ea0d4a
commit
0ca78c8769
2 changed files with 25 additions and 30 deletions
|
@ -96,26 +96,6 @@
|
||||||
callback(data);
|
callback(data);
|
||||||
})
|
})
|
||||||
.fail(function(xhr) {
|
.fail(function(xhr) {
|
||||||
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 (typeof xhr.responseJSON !== 'undefined') {
|
|
||||||
c.flash('fail', xhr.responseJSON.error);
|
|
||||||
} else if (typeof xhr.statusText !== 'undefined' && uri !== '/postinstall') {
|
|
||||||
var errorMessage = xhr.status+' '+xhr.statusText;
|
|
||||||
// If some more text is available, display it to user.
|
|
||||||
if (typeof xhr.responseText !== 'undefined') {
|
|
||||||
errorMessage += ' - ' + xhr.responseText;
|
|
||||||
}
|
|
||||||
c.flash('fail', y18n.t('api_not_responding', [errorMessage]));
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
|
@ -131,9 +111,23 @@
|
||||||
} else {
|
} else {
|
||||||
c.flash('fail', y18n.t('error_occured'));
|
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 {
|
} else {
|
||||||
c.flash('fail', y18n.t('error_server'));
|
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') {
|
if (uri !== '/postinstall') {
|
||||||
store.clear('slide');
|
store.clear('slide');
|
||||||
|
|
|
@ -55,13 +55,14 @@
|
||||||
"unauthorized" : "Unauthorized",
|
"unauthorized" : "Unauthorized",
|
||||||
"error_occured" : "An error occured, try again",
|
"error_occured" : "An error occured, try again",
|
||||||
"error_server" : "Server error",
|
"error_server" : "Server error",
|
||||||
|
"error_server_unexpected" : "Unexpected server error (%s)",
|
||||||
"error_select_domain" : "You should indicate a domain",
|
"error_select_domain" : "You should indicate a domain",
|
||||||
"error_modify_something" : "You should modify something",
|
"error_modify_something" : "You should modify something",
|
||||||
"non_compatible_api" : "Non-compatible API",
|
"non_compatible_api" : "Non-compatible API",
|
||||||
"warning_first_user" : "You probably need to <a href='#/users/create' class='alert-link'>create a user</a> first.",
|
"warning_first_user" : "You probably need to <a href='#/users/create' class='alert-link'>create a user</a> first.",
|
||||||
"unknown_action" : "Unknown action %s",
|
"unknown_action" : "Unknown action %s",
|
||||||
"unknown_argument" : "Unknown argument : %s",
|
"unknown_argument" : "Unknown argument : %s",
|
||||||
"api_not_responding" : "API is not responding (Error : %s)",
|
"api_not_responding" : "API is not responding",
|
||||||
"error_retrieve_feed" : "Could not retrieve feed : %s",
|
"error_retrieve_feed" : "Could not retrieve feed : %s",
|
||||||
|
|
||||||
"confirm_delete" : "Are you sure you want to delete %s ?",
|
"confirm_delete" : "Are you sure you want to delete %s ?",
|
||||||
|
|
Loading…
Reference in a new issue