سؤال

I have used XMLRPC library for android in my Android Project that uses Magento's API.
I am getting an error when I send a request to the Magento Store through using Magneto API.
That Error contains "ERROR CODE" with it.

The Error is like :

                                               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 the Exception just like how we fetch the Error message like as below:

try
{
  ......
  ......
}
catch(Exception e)
{
  Log.i("Error",e.getMessage());
}
هل كانت مفيدة؟

المحلول

You already have error message, it just empty in this case. 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 call XMLRPCFault object (src/org/xmlrpc/android/XMLRPCFault.java) which extends XMLRPCException. Here is 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 show you "XMLRPC Fault: [code 101]", where faultString='' (empty) and faultCode=101. Btw, this is urlopen error [Errno 101] "Network is unreachable". It can occurs if you use some proxy.

Now about error handling: you use server.py as XML-RPC server. But in code no any error handlers defined. You can do it by adding next lines after 'class MyFunc:' string:

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

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top