1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #723: Improve error handling in Sunstone/oZones client-side.

*Removed unused error regexps
*Fixed used regexps
*Do not report "server cannot be reached" all the time, do it only once.
*Do not crash when a server exception occurs: inform user and direct to server logs
This commit is contained in:
Hector Sanjuan 2011-07-26 16:53:43 +02:00 committed by Ruben S. Montero
parent d7c66549c6
commit 03237cf3e3
3 changed files with 30 additions and 23 deletions

View File

@ -21,7 +21,12 @@ var oZones = {
var error = {};
if (resp.responseText)
{
error = JSON.parse(resp.responseText);
try {
error = JSON.parse(resp.responseText);
}
catch (e) {
error.error = {message: "It appears there was a server exception. Please check server's log."};
};
}
else
{

View File

@ -21,7 +21,12 @@ var OpenNebula = {
var error = {};
if (resp.responseText)
{
error = JSON.parse(resp.responseText);
try {
error = JSON.parse(resp.responseText);
}
catch (e) {
error.error = {message: "It appears there was a server exception. Please check server's log."};
};
}
else
{

View File

@ -321,43 +321,40 @@ function onError(request,error_json) {
var m;
var message = error_json.error.message;
if ( typeof onError.disabled == 'undefined' ) {
onError.disabled=false;
}
//redirect to login if unauthenticated
if (error_json.error.http_status=="401") {
window.location.href = "login";
onError.disabled=false;
return false;
};
if (!message){
notifyError("Cannot contact server: is Sunstone server running and reachable?");
if (!onError.disabled){
notifyError("Cannot contact server: is it running and reachable?");
onError.disabled=true;
}
return false;
} else {
onError.disabled=false;
}
//Parse known errors:
var action_error = /^\[(\w+)\] Error trying to (\w+) (\w+) \[(\w+)\].*Reason: (.*)\.$/;
var action_error_noid = /^\[(\w+)\] Error trying to (\w+) (\w+) (.*)\.$/;
var get_error = /^\[(\w+)\] Error getting (\w+) \[(\w+)\]\.$/;
var auth_error = /^\[(\w+)\] User \[.\] not authorized to perform (\w+) on (\w+) \[?(\w+)\]?\.?$/;
var get_error = /^\[(\w+)\] Error getting ([\w ]+) \[(\d+)\]\.$/;
var auth_error = /^\[(\w+)\] User \[(\d+)\] not authorized to perform action on ([\w ]+).$/;
if (m = message.match(action_error)) {
if (m = message.match(get_error)) {
method = m[1];
action = m[2];
object = m[3];
id = m[4];
reason = m[5];
} else if (m = message.match(action_error_noid)) {
method = m[1];
action = m[2];
object = m[3];
reason = m[4];
} else if (m = message.match(get_error)) {
method = m[1];
action = "SHOW";
action = "Show";
object = m[2];
id = m[3];
} else if (m = message.match(auth_error)) {
method = m[1];
action = m[2];
object = m[3];
id = m[4];
object = m[3];
reason = "Unauthorized";
}
if (m) {