Author:   Lars Michelsen <[email protected]>
Date:     Sun Nov  4 17:18:38 2012 +0100
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Sun Nov  4 17:18:38 2012 +0100

Better handling of HTTP errors in ajax transactions

---

 ChangeLog                           |    1 +
 share/frontend/nagvis-js/js/ajax.js |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9dc2253..d9dd4de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@ Core:
 
 Frontend:
   * Hiding rotations table on overview page when no rotations configured
+  * Better handling of HTTP errors in ajax transactions
   * Bugfix: Re-added "loading..." message on page redering
 
 1.7.2
diff --git a/share/frontend/nagvis-js/js/ajax.js 
b/share/frontend/nagvis-js/js/ajax.js
index cc19964..ee8c556 100644
--- a/share/frontend/nagvis-js/js/ajax.js
+++ b/share/frontend/nagvis-js/js/ajax.js
@@ -120,6 +120,12 @@ function ajaxError(e) {
                     0, 'ajaxError');
 }
 
+function httpError(text) {
+    frontendMessage({'type': 'CRITICAL',
+                     'title': 'HTTP error',
+                     'message': text});
+}
+
 function phpError(text) {
     frontendMessage({'type': 'CRITICAL',
                      'title': 'PHP error',
@@ -172,6 +178,20 @@ function getAsyncRequest(sUrl, bCacheable, callback, 
callbackParams) {
         oRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 
00:00:00 GMT");
         oRequest.onreadystatechange = function() {
             if(oRequest && oRequest.readyState == 4) {
+                // Handle unexpected HTTP responses. Normally everything comes 
with code 200.
+                // If something different is received, something must be 
wrong. Raise a whole
+                // screen message in this case.
+                if(oRequest.status != 200) {
+                    var msg = 'HTTP-Response: ' + oRequest.status;
+                    if(oRequest.responseText != '') {
+                        msg += ' - Body: ' + oRequest.responseText;
+                    } else if(oRequest.status == 500) {
+                        msg += ' - Internal Server Error (Take a look at the 
apache error log for details.)'
+                    }
+                    httpError(msg);
+                    return;
+                }
+
                 frontendMessageRemove('ajaxError');
                 if(oRequest.responseText.replace(/\s+/g, '').length === 0) {
                     if(bCacheable)


------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to