orhanobut / wasp

Compact and easy to use, 'all-in-one' android network solution

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does RetryPolicy work?

nologinatgit opened this issue · comments

I have the following interface:

  @GET("/information")
  @RetryPolicy(timeout = 10000)
  void GetInformation(Callback< List< Information>> callback);

This is my setup:

myService = new Wasp.Builder(MainActivity.this)
        .setEndpoint(BASE_API_URL)
        .build()
        .create(IMyService.class);

I call it like this:

 myService .GetInformation(new Callback< List< Information>>()
        {
          @Override
          public void onSuccess(Response response, List< Information> informations)
          {
            Log.w("DEBUG", "Success");            
          }

          @Override
          public void onError(WaspError error)
          {
            Log.w("DEBUG", error);
          }
        });`

Sometimes I get this back:

 Wasp Error:  Status Code: 0 Url http://mysite.com/api/information
     at com.orhanobut.wasp.VolleyNetworkStack$VolleyListener.onErrorResponse(VolleyNetworkStack.java:171)
     at com.android.volley.Request.deliverError(Request.java:590)
     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101)
     at android.os.Handler.handleCallback(Handler.java:615)
     at android.os.Handler.dispatchMessage(Handler.java:92)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:4802)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:511)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
     at dalvik.system.NativeStart.main(Native Method)

What does code 0 mean? If I set the retry policy, shouldn't it retry a few times? How should I set it? The Wiki is very thin.

Error information indeed doesn't contain enough information about what happened. We have an open issue for improving. You also need to add other values, currently you only set timeout.

@RetryPolicy(timeout = 10000, maxNumRetries=3, backoffMultiplier=0.75)

On the other hand, default values are set if they are null. In your case it should retry 3 times but I also don't know the reason, usually status code=0 is returned when there is no connection established.

I'll try to spare some time to improve wasperror in order to provide much better information.