Search code examples
androidpostrequestloopjandroid-async-http

How do I get the Throwable (error) at android-async-http from loopj?


I am using the (I guess) quite popular library from LoopJ (https://github.com/loopj/android-async-http) to make GET and POST requests. Everything if working fine, but when it comes to cookie-handling I got some errors. Occasionally the POST-Login request in my app fails for no reason. In that case, the onFailure-method of the POST request is called correctly:

        @Override
        public void onFailure(Throwable error, String content) {
            Log.e("custom onFailure POST", error.getMessage());
            cb.onTaskComplete("LOGIN_FAILED");
        }

The strange thing is, that both "Throwable error" and "String content" are NULL-objects. That makes it really hard to analyze to problem of logging the user in into my app. Can someone tell me, how to get the source of the failure? Are there other methods I can implement to get a better fail-repost from the request?


Solution

  • The easiest approach would be to debug your application, placing a breakpoint in the onFailure method. When it stops on that breakpoint, look at the call stack to find where the error originated from.

    Also, within your method, you could call Thread.currentThread().getStackTrace() then loop through the array of StackTraceElement[] - so you can output info to your logs (or stdout etc.) so you don't need the app in debug.