]> iEval git - fonbot.git/blobdiff - src/ro/ieval/fonbot/PollResultCallback.java
Stop long polling on error
[fonbot.git] / src / ro / ieval / fonbot / PollResultCallback.java
index e75ffce2f3548f4c541a83e17790c605cd8453b0..46e3eda83e39cc4ed15455ea0fc64f05f6c4f787 100644 (file)
@@ -3,6 +3,7 @@ package ro.ieval.fonbot;
 import static ro.ieval.fonbot.Utils.toNonNull;
 
 import java.io.InputStream;
+import org.eclipse.jdt.annotation.Nullable;
 
 import org.json.JSONArray;
 import org.json.JSONObject;
@@ -53,10 +54,12 @@ final class PollResultCallback implements ResultCallback {
        }
 
        @Override
-       public void onResult(int responseCode, String responseMessage,
-                       InputStream inputStream) {
-               if(responseCode!=200)
+       public void onResult(final int responseCode, final String responseMessage, final @Nullable InputStream inputStream) {
+               if(responseCode != 200 || inputStream==null){
+                       if(responseCode != 204)
+                               throw new RuntimeException("Bad HTTP response code: "+responseCode);
                        return;
+               }
 
                final Handler handler=new Handler(Looper.getMainLooper());
 
@@ -73,7 +76,7 @@ final class PollResultCallback implements ResultCallback {
 
                                final JSONArray jsonargs=object.getJSONArray("args");
                                final String command=object.getString("command");
-                               final Address replyTo=new Address(toNonNull(Protocol.HTTP), object.getString("replyto"));//NOPMD address depends on command
+                               final Address replyTo=new Address(toNonNull(Protocol.HTTP), object.getString("replyto"), object.has("requestid") ? object.getString("requestid") : null);//NOPMD address depends on command
                                final String[] args=new String[jsonargs.length()];
                                for(int j=0;j<args.length;j++)
                                        args[j]=jsonargs.getString(j);
@@ -99,6 +102,7 @@ final class PollResultCallback implements ResultCallback {
        @Override
        public void onError(final String error) {
                Log.e("PollResultCallback", "onError: "+error);
+               throw new RuntimeException(error);
        }
 
 }
This page took 0.024859 seconds and 4 git commands to generate.