Show
Ignore:
Timestamp:
04/23/08 09:24:37 (5 months ago)
Author:
richi
Message:

javascript: fixed json-rpc bug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/javascript/stub-json-rpc-debug.js

    r1170 r1562  
    2828        success: function(o) { 
    2929            var rpcObj = o.responseText.parseJSON(); 
    30             if ( rpcObj.error === null ) { 
    31                 for (var i=0; i < reqRespMapping.length; i++) { 
    32                     if (rpcObj.id === reqRespMapping[i].id) { 
    33                         var classAndMethod = reqRespMapping[i].method.split("."); 
    34                         console.info("Stubbles::REQID " + rpcObj.id +  " :: Calling callback method callback__" + classAndMethod[1] + "("+rpcObj.id+", "+rpcObj.result+", "+rpcObj.error+")"); 
    35                         var methodName = 'callback__' + classAndMethod[1]; 
     30            for (var i=0; i < reqRespMapping.length; i++) { 
     31                if (rpcObj.id === reqRespMapping[i].id) { 
     32                    var classAndMethod = reqRespMapping[i].method.split("."); 
     33                    console.info("Stubbles::REQID " + rpcObj.id +  " :: Calling callback method callback__" + classAndMethod[1] + "("+rpcObj.id+", "+rpcObj.result+", "+rpcObj.error+")"); 
     34                    var methodName = 'callback__' + classAndMethod[1]; 
    3635 
    37                         // call callback method on clientObj 
    38                         clientObj[methodName].call(clientObj, rpcObj.id, rpcObj.result, rpcObj.error); 
    39                         return; 
     36                    // call callback method on clientObj 
     37                    if ( rpcObj.error === null ) { 
     38                      clientObj[methodName].call(clientObj, rpcObj.id, rpcObj.result, rpcObj.error); 
     39                    } else { 
     40                      console.error("Stubbles::REQID " + rpcObj.id +  " :: ERROR: " + rpcObj.error); 
     41                      clientObj[methodName].call(clientObj, rpcObj.id, null, rpcObj.error); 
    4042                    } 
     43                    return; 
    4144                } 
    42                 console.error("Stubbles::REQID " + rpcObj.id +  " :: Invalid request id."); 
    43                 throw 'stubbles: no related request id for response id found - mapping in js obj reqRespMapping failed!'; 
    44             } else { 
    45                 console.error("Stubbles::REQID " + rpcObj.id +  " :: ERROR: " + rpcObj.error); 
    46                 throw rpcObj.error; 
    4745            } 
     46            console.error("Stubbles::REQID " + rpcObj.id +  " :: Invalid request id."); 
     47            var errorMsg = 'stubbles: no related request id for response id found - mapping in js obj reqRespMapping failed!'; 
     48            clientObj[methodName].call(clientObj, rpcObj.id, null, errorMsg); 
    4849        }, 
    4950        failure: function(o) { 
    5051            console.error("Stubbles::REQID n/a :: ERROR: HTTP Request failed."); 
    51             throw 'stubbles: callback error due to bad request from service (instead of HTTP status code 200)'; 
     52            var errorMsg = 'stubbles: callback error due to bad request from service (instead of HTTP status code 200)'; 
     53            clientObj[methodName].call(clientObj, rpcObj.id, null, errorMsg); 
    5254        } 
    5355    }; 
  • trunk/src/main/javascript/stub-json-rpc.js

    r1170 r1562  
    2828        success: function(o) { 
    2929            var rpcObj = o.responseText.parseJSON(); 
    30             if ( rpcObj.error === null ) { 
    31                 for (var i=0; i < reqRespMapping.length; i++) { 
    32                     if (rpcObj.id === reqRespMapping[i].id) { 
    33                         var classAndMethod = reqRespMapping[i].method.split("."); 
    34                         var methodName = 'callback__' + classAndMethod[1]; 
     30            for (var i=0; i < reqRespMapping.length; i++) { 
     31                if (rpcObj.id === reqRespMapping[i].id) { 
     32                    var classAndMethod = reqRespMapping[i].method.split("."); 
     33                    var methodName = 'callback__' + classAndMethod[1]; 
    3534 
    36                         // call callback method on clientObj 
    37                         clientObj[methodName].call(clientObj, rpcObj.id, rpcObj.result, rpcObj.error); 
    38                         return; 
     35                    // call callback method on clientObj 
     36                    if ( rpcObj.error === null ) { 
     37                      clientObj[methodName].call(clientObj, rpcObj.id, rpcObj.result, rpcObj.error); 
     38                    } else { 
     39                      clientObj[methodName].call(clientObj, rpcObj.id, null, rpcObj.error); 
    3940                    } 
     41                    return; 
    4042                } 
    41                 throw 'stubbles: no related request id for response id found - mapping in js obj reqRespMapping failed!'; 
    42             } else { 
    43                 throw rpcObj.error; 
    4443            } 
     44            var errorMsg = 'stubbles: no related request id for response id found - mapping in js obj reqRespMapping failed!'; 
     45            clientObj[methodName].call(clientObj, rpcObj.id, null, errorMsg); 
    4546        }, 
    4647        failure: function(o) { 
    47             throw 'stubbles: callback error due to bad request from service (instead of HTTP status code 200)'; 
     48            var errorMsg = 'stubbles: callback error due to bad request from service (instead of HTTP status code 200)'; 
     49            clientObj[methodName].call(clientObj, rpcObj.id, null, errorMsg); 
    4850        } 
    4951    };