mihazoubek / json-xml-rpc

Automatically exported from code.google.com/p/json-xml-rpc
0 stars 0 forks source link

Bug on line 427 (if response.error is null, but not undefined, error condition is processed) #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Define a service:

  svc = new rpc.ServiceProxy("/app/test/call/jsonrpc", {asynchronus: false, protocol: 'JSON-RPC', sanitize: true, methods:['add']})

2. Call the service's add function:

  svc.add({params:[50,2]});

What is the expected output? What do you see instead?

  It is expected that no error will occur. Instead the following TypeError occurs:

Uncaught TypeError: Cannot read property 'message' of null

What version of the product are you using? On what operating system?

  rpc-client v 0.8.0.2 (from the following url):

  http://json-xml-rpc.googlecode.com/files/rpc-client-javascript-0.8.0.2.zip

Please provide any additional information below.

  On line 427 of rpc.js, there is this statement:

  if(response.error !== undefined){

  When using google chrome to pause the script execution at line 427, i see that response.error is "null" (not undefined), and response.result is 52 (expected result). However, since the expression "response.error !== undefined" evaluates to True, the error branch is executed. resulting in the TypeError message printed to console. Also, my callback "onSuccess" function (when provided) is never executed. 

I fixed this for my purposes by changing the line to:

if(response.error !== undefined && response.error !== null){

  Though it seems "response.error != undefined" also works.

  This is the value of the response object when script execution is halted at line 427:

response = {
  error: null
  id: 33
  result: 52 
  version: "1.1"
}

NOTE: The jsonrpc service is a web2py function defined as follows:

@service.xmlrpc
@service.jsonrpc
def add(a,b):
  return a + b

The code is in a controller called test.py within an application called app. 

Using the python module xmlrpclib to access this service works as expected.

Original issue reported on code.google.com by Kas...@gmail.com on 23 Sep 2011 at 6:18