Author:   Lars Michelsen <[email protected]>
Date:     Wed Aug 24 22:54:53 2011 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Wed Aug 24 22:54:53 2011 +0200

Removed error prefix in ajax responses

---

 TODO                                         |    1 +
 share/frontend/nagvis-js/js/ajax.js          |   33 ++++++++-----------------
 share/server/core/ajax_handler.php           |    2 +-
 share/server/core/classes/CoreExceptions.php |    2 +-
 4 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/TODO b/TODO
index fb63118..0a86cb9 100644
--- a/TODO
+++ b/TODO
@@ -43,6 +43,7 @@ Relative Koordinaten:
 - Main Config Zugriff über kürzere Aufrufe. Beispiel: $CORE->cfg('', '');
 - Weathermap Linien Perfdata Berechnungen nach check_command aufräumen
 - MapCfg Config Array aufräumen
+- ajax Funktionen aufräumen/konsolidieren
 
 
 *** Linien (Auch für neue Automap wichtig!) ***
diff --git a/share/frontend/nagvis-js/js/ajax.js 
b/share/frontend/nagvis-js/js/ajax.js
index 265d5b4..8352888 100644
--- a/share/frontend/nagvis-js/js/ajax.js
+++ b/share/frontend/nagvis-js/js/ajax.js
@@ -173,12 +173,10 @@ function getAsyncRequest(sUrl, bCacheable, callback, 
callbackParams) {
                     // Error handling for the AJAX methods
                     if(responseText.match(/^Notice:|^Warning:|^Error:|^Parse 
error:/)) {
                         phpError(responseText);
-                    } else if(responseText.match(/^NagVisError:/)) {
-                        frontendMessage(eval('( 
'+responseText.replace(/^NagVisError:/, '')+')'));
                     } else {
                         // Handle responses of json objects - including eval 
and wron response
                         // error handling and clearing
-                        var oResponse = handleJsonResponse(sUrl, responseText)
+                        var oResponse = handleJsonResponse(sUrl, responseText);
 
                         if(oResponse)
                             callback(oResponse, callbackParams);
@@ -239,7 +237,7 @@ function getSyncRequest(sUrl, bCacheable, bRetryable) {
         if(responseText !== '') {
             // Handle responses of json objects - including eval and wron 
response
             // error handling and clearing
-            sResponse = handleJsonResponse(sUrl, responseText)
+            sResponse = handleJsonResponse(sUrl, responseText);
         } else {
             // Remove the invalid code from cache
             cleanupQueryCache(sUrl);
@@ -281,23 +279,12 @@ function getSyncRequest(sUrl, bCacheable, bRetryable) {
                 // Error handling for the AJAX methods
                 if(responseText.match(/^Notice:|^Warning:|^Error:|^Parse 
error:/)) {
                     phpError(responseText);
-                } else if(responseText.match(/^NagVisError:/)) {
-                    responseText = responseText.replace(/^NagVisError:/, '');
-                    var oMsg = eval('( '+responseText+')');
-
-                    // Handle application message/error
-                    // FIXME: Param2: 30 and the message will be shown for 
maximum 30 seconds
-                    frontendMessage(oMsg);
-                    oMsg = null;
-
-                    // Clear the response
-                    sResponse = '';
                 } else {
                     // Handle responses of json objects - including eval and 
wron response
                     // error handling and clearing
                     sResponse = handleJsonResponse(sUrl, responseText)
 
-                    if(sResponse !== null && bCacheable) {
+                    if(sResponse !== '' && bCacheable) {
                         // Cache that answer (only when no error/warning/...)
                         updateQueryCache(url, timestamp, responseText);
                     }
@@ -317,17 +304,22 @@ function getSyncRequest(sUrl, bCacheable, bRetryable) {
 
 function handleJsonResponse(sUrl, responseText) {
     try {
-        sResponse = eval('( '+responseText+')');
+        oResponse = eval('( '+responseText+')');
         frontendMessageRemove('jsonError');
-        return sResponse;
     } catch(e) {
         jsonError("Invalid json response:\nTime:" + iNow + "\nURL: " + sUrl + 
"\nResponse: " + responseText);
         return '';
     }
 
-    if(typeof(sResponse) !== 'object') {
+    if(typeof(oResponse) !== 'object') {
         jsonError("Invalid json response:\nTime:" + iNow + "\nURL: " + sUrl + 
"\nResponse: " + responseText);
         return '';
+    } else {
+        if(isset(oResponse.type) && isset(oResponse.message)) {
+            frontendMessage(oResponse);
+            return '';
+        }
+        return oResponse;
     }
 }
 
@@ -427,9 +419,6 @@ function postSyncRequest(sUrl, sParams) {
                 oResponse.type = 'CRITICAL';
                 oResponse.message = "PHP error in ajax request 
handler:\n"+responseText;
                 oResponse.title = "PHP error";
-            } else if(responseText.match(/^NagVisError:/)) {
-                responseText = responseText.replace(/^NagVisError:/, '');
-                oResponse = eval('( '+responseText+')');
             } else {
                 // Handle invalid response (No JSON format)
                 try {
diff --git a/share/server/core/ajax_handler.php 
b/share/server/core/ajax_handler.php
index ceac0a1..7204b1f 100644
--- a/share/server/core/ajax_handler.php
+++ b/share/server/core/ajax_handler.php
@@ -65,7 +65,7 @@ try {
 } catch(NagVisException $e) {
     echo $e;
 } catch(Exception $e) {
-    echo 'NagVisError:'.json_encode(Array(
+    echo json_encode(Array(
         'type'    => 'error',
         'message' => $e->getMessage(),
         'title'   => l('ERROR - Unexpected exception'),
diff --git a/share/server/core/classes/CoreExceptions.php 
b/share/server/core/classes/CoreExceptions.php
index a25e308..cc89c64 100644
--- a/share/server/core/classes/CoreExceptions.php
+++ b/share/server/core/classes/CoreExceptions.php
@@ -44,7 +44,7 @@ class NagVisException extends Exception {
     }
 
     function __toString() {
-        return 'NagVisError:'.json_encode($this->e);
+        return json_encode($this->e);
     }
 }
 


------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to