commit 0e8e87ac2f3de1c26baf52df65f033e05eff5df9
Author: Kostas Papadimitriou <vinilios@gmail.com>
Date:   Mon Jul 11 18:09:25 2011 +0300

    minor improvements on ui error handlers
    
    display specific code/message (-5, "UI Error") for js exceptions
    display exception info and firebug trace if in DEBUG mode

diff --git a/ui/static/synnefo.js b/ui/static/synnefo.js
index b767fb4..abd60aa 100644
--- a/ui/static/synnefo.js
+++ b/ui/static/synnefo.js
@@ -54,7 +54,7 @@ $.ajaxSetup({
             try {
                 ajax_error(jqXHR.status, undefined, 'Unknown', jqXHR.responseText);
             } catch(err) {
-                ajax_error(0, undefined, 'Unknown', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Unknown', err);
             }
         }
 
@@ -335,7 +335,7 @@ function update_vms(interval) {
             try {
                 ajax_error(jqXHR.status, undefined, 'Update VMs', jqXHR.responseText);
             } catch(err) {
-                ajax_error(0, undefined, 'Update VMs', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Update VMs', err);
             }
             return false;
             },
@@ -356,7 +356,7 @@ function update_vms(interval) {
                     //servers = data.servers.values;
                     update_servers_data(data.servers.values, data);
                     update_machines_view(data);
-                } catch(err) { ajax_error('400', undefined, 'Update VMs', jqXHR.responseText);}
+                } catch(err) { ajax_error(-5, "UI Error", 'Update VMs', err);}
             } else if (jqXHR.status != 304){
                 try { console.info('update_vms callback:' + jqXHR.status ) } catch(err) {}
                 /*
@@ -481,7 +481,7 @@ function update_networks(interval) {
             try {
                 ajax_error(jqXHR.status, undefined, 'Update networks', jqXHR.responseText);
             } catch(err) {
-                ajax_error(0, undefined, 'Update networks', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Update networks', err);
             }
             return false;
             },
@@ -503,7 +503,7 @@ function update_networks(interval) {
                     update_servers_data(data.servers.values, data);
                     jQuery.parseJSON(data);
                     update_network_names(data);
-                } catch(err) { ajax_error('400', undefined, 'Update networks', jqXHR.responseText);}
+                } catch(err) { ajax_error(-5, "UI Error", 'Update networks', err);}
             } else if (jqXHR.status == 304) {
                 update_network_names();
             }
@@ -546,7 +546,7 @@ function update_network_names(servers_data) {
             try {
                 ajax_error(jqXHR.status, undefined, 'Update network names', jqXHR.responseText);
             } catch(err) {
-                ajax_error(0, undefined, 'Update network names', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Update network names', err);
             }
             return false;
             },
@@ -563,7 +563,7 @@ function update_network_names(servers_data) {
                     jQuery.parseJSON(data);
                     update_networks_view(servers_data, data);
                 } catch(err) {
-                    ajax_error('400', undefined, 'Update network names', jqXHR.responseText);
+                    ajax_error(-5, "UI Error", 'Update network names', err);
                 }
             } else if (jqXHR.status == 304) {
                 update_networks_view(servers_data);
@@ -595,7 +595,7 @@ function update_images() {
                     try {
                         ajax_error(jqXHR.status, undefined, 'Update Images', jqXHR.responseText);
                     } catch(err) {
-                        ajax_error(0, undefined, 'Update Images', jqXHR.responseText);
+                        ajax_error(-5, "UI error", 'Update Images', err);
                     }
                 },
         success: function(data, textStatus, jqXHR) {
@@ -721,7 +721,7 @@ function update_flavors() {
             try {
                 ajax_error(jqXHR.status, undefined, 'Update Flavors', jqXHR.responseText);
             } catch (err) {
-                ajax_error(err);
+                ajax_error(-5, "UI Error", "Update Flavors", err);
             }
             // start updating vm list
             update_vms(UPDATE_INTERVAL);
@@ -871,7 +871,7 @@ function create_vm(machineName, imageRef, flavorRef){
                     try {
                         ajax_error(jqXHR.status, undefined, 'Create VM', jqXHR.responseText);
                     } catch(err) {
-                        ajax_error(0, undefined, 'Create VM', jqXHR.responseText);
+                        ajax_error(-5, "UI Error", 'Create VM', err);
                     }
            },
     success: function(data, textStatus, jqXHR) {
@@ -1292,7 +1292,7 @@ function get_metadata(serverID, keys_only) {
                 $("a#metadata-scrollable").data('overlay').close();
                 ajax_error(jqXHR.status, undefined, 'Get metadata', jqXHR.responseText);
             } catch (err) {
-                ajax_error(err);
+                ajax_error(-5, "UI Error", "Get metadata", err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1324,7 +1324,7 @@ function delete_metadata(serverID, meta_key) {
                 $("a#metadata-scrollable").data('overlay').close();
                 ajax_error(jqXHR.status, undefined, 'Delete metadata', jqXHR.responseText);
             } catch (err) {
-                ajax_error(err);
+                ajax_error(-5, "UI Error", "Delete metadata", err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1355,7 +1355,7 @@ function update_metadata(serverID, meta_key, meta_value) {
                 $("a#metadata-scrollable").data('overlay').close();
                 ajax_error(jqXHR.status, undefined, 'add metadata', jqXHR.responseText);
             } catch (err) {
-                ajax_error(err);
+                ajax_error(-5, "UI Error", "add metadata", err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1427,7 +1427,7 @@ function create_network(networkName){
                 $("a#networkscreate").overlay().close();
                 ajax_error(jqXHR.status, undefined, 'Create network', jqXHR.responseText);
             } catch (err) {
-                ajax_error(err);
+                ajax_error(-5, "UI Error", "Create network", err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1473,7 +1473,7 @@ function rename_network(networkID, networkName){
             try {
                 ajax_error(jqXHR.status, undefined, 'Rename network', jqXHR.responseText);
             } catch (err) {
-                ajax_error(0, undefined, 'Rename network', jqXHR.responseText);
+                ajax_error(-1, "UI Error", 'Rename network', err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1560,7 +1560,7 @@ function add_server_to_network(networkID, serverIDs, serverNames, serverStates)
                 $("a#add-machines-overlay").data('overlay').close();
                 ajax_error(jqXHR.status, undefined, 'Add server to network', jqXHR.responseText);
             } catch (err) {
-                ajax_error(0, undefined, 'Add server to network', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Add server to network', err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1608,7 +1608,7 @@ function remove_server_from_network(networkIDs, serverIDs, serverNames, serverSt
             try {
                 ajax_error(jqXHR.status, undefined, 'Remove server form network', jqXHR.responseText);
             } catch (err) {
-                ajax_error(0, undefined, 'Remove server form network', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Remove server form network', err);
             }
         },
         success: function(data, textStatus, jqXHR) {
@@ -1648,7 +1648,7 @@ function set_firewall(networkID, serverID, profile) {
             try {
                 ajax_error(jqXHR.status, undefined, 'Set firewall profile', jqXHR.responseText);
             } catch (err) {
-                ajax_error(0, undefined, 'Set firewall profile', jqXHR.responseText);
+                ajax_error(-5, "UI Error", 'Set firewall profile', err);
             }
         },
         success: function(data, textStatus, jqXHR) {
diff --git a/ui/templates/home.html b/ui/templates/home.html
index 1d620fc..ce581c1 100644
--- a/ui/templates/home.html
+++ b/ui/templates/home.html
@@ -74,6 +74,7 @@ or implied, of GRNET S.A.
         var LOGOUT_REDIRECT = undefined;
         var INVITATIONS_URL = "{% url invitations %}"
         var INVITATIONS_TITLE = "{% trans "Invitations" %}"
+        var APP_DEBUG = {% if DEBUG %}true{% else %}false{% endif %};
 
         // server statuses and transitions
         var STATUSES = {
@@ -195,8 +196,18 @@ or implied, of GRNET S.A.
                 if (serverName) {
                     serverName = "<p>{% trans "Server" %}: " + serverName + "</p>";
                 }
+
                 if ((errors[0].details === undefined) || (errors[0].details === "")) {
                     details = ERRORS["NO_DETAILS"];
+                    
+                    // if no details message show debug info
+                    if (window.APP_DEBUG) {
+                        details = responseText;
+                        try {
+                            console.trace();
+                        } catch (err) {
+                        }
+                    }
                 } else {
                     details = errors[0].details;
                 }
@@ -207,7 +218,13 @@ or implied, of GRNET S.A.
                 $("#error-success .password-container").hide();
                 $("#error-success .popup-details").addClass("popup-details-error");
                 $("#error-success .popup-separator").addClass("popup-separator-error");
-                $("#error-success .popup-details").html("<p>" + (errors[0].message || ERRORS[errors[0].code]) + "</p>" + serverName + "<p>{% trans "Action" %}: " + action + "</p><p>{% trans "Code" %}: " + errors[0].code + "<p><a class='expand-details' href='#'>{% trans 'Details' %}</a><div class='more-details'>" + details + "</div></p>");
+                $("#error-success .popup-details").html("<p>" + 
+                    (errors[0].message || ERRORS[errors[0].code] || serverID) + 
+                    "</p>" + serverName + "<p>{% trans "Action" %}:" + 
+                    action + "</p><p>{% trans "Code" %}: " + errors[0].code + 
+                    "<p><a class='expand-details' href='#'>{% trans 'Details' %}</a><div class='more-details'>" + 
+                    details + "</div></p>");
+
             } else if (ERRORS[status] !== undefined) {
                 if (serverID === undefined) {
                     //eg no_images, no_flavors cases
diff --git a/ui/views.py b/ui/views.py
index 2404298..46d0424 100644
--- a/ui/views.py
+++ b/ui/views.py
@@ -57,7 +57,8 @@ def home(request):
                'request': request,
                'current_lang': get_language() or 'en',
                'update_interval': UPDATE_INTERVAL,
-               'image_icons': IMAGE_ICONS,}
+               'image_icons': IMAGE_ICONS,
+               'DEBUG': settings.DEBUG}
     return template('home', context)
 
 def machines(request):
