How to get error code in Android XMLRPC library

I have used in my Android project which uses Magento API. I am getting an error when I submit a request to a Magento store via the Magneto API. This error contains " ". XMLRPC library for android



ERROR CODE

Mistake:

                                               this code
                                                  ||
                                                  \/
org.xmlrpc.android.XMLRPCFault: XMLRPC Fault:  [code 101]  
at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:308)
at org.xmlrpc.android.XMLRPCMethod.run(XMLRPCMethod.java:33)
.
.
.

      

Does anyone know how to get this error code from Exception in the same way that we get the error message like below:

try
{
  ......
  ......
}
catch(Exception e)
{
  Log.i("Error",e.getMessage());
}

      

+3


source to share


1 answer


You already have an error message, it's just blank in this case. Take a look at src / org / xmlrpc / android / XMLRPCClient.java (line 216):

if (tag.equals(Tag.FAULT)) {
    pullParser.nextTag(); // Tag.VALUE (<value>)
    Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
    String faultString = (String) map.get(Tag.FAULT_STRING);
    int faultCode = (Integer) map.get(Tag.FAULT_CODE);
    entity.consumeContent();
    throw new XMLRPCFault(faultString, faultCode);
}

      

Here we name the object XMLRPCFault (src / org / xmlrpc / android / XMLRPCFault.java) which extends XMLRPCException. Here's the main part:

public XMLRPCFault(String faultString, int faultCode) {
    super("XMLRPC Fault: " + faultString + " [code " + faultCode + "]");
    this.faultString = faultString;
    this.faultCode = faultCode;
}

      



As you can see, this method shows you "XMLRPC error: [code 101]" where faultString = '' (empty) and faultCode = 101. Btw, this is urlopen [Errno 101] "Network down" error. This can happen if you are using some kind of proxy.

Now for error handling: you are using server.py as an XML-RPC server. But no error handlers are defined in the code. You can do this by adding the following lines after the line "class MyFunc:":

class MyFuncs:
    def _dispatch(self, method, args):
    try:
        return getattr(self, method)(*args)
    except:
        handle_logging()
...

      

and execute your log in handle_logging (). More details here: https://docs.python.org/2/library/logging.html#logging.Logger.exception

+1


source







All Articles