/gist:f91bf03c3adeb7169420 Secret
Created
June 19, 2015 10:19
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| + * Sends an asynchronous or synchronous UIDL request to the server using the | |
| + * given URI. | |
| + * | |
| + * @param uri | |
| + * The URI to use for the request. May includes GET parameters | |
| + * @param payload | |
| + * The contents of the request to send | |
| + * @param retry | |
| + * true when a status code 0 should be retried | |
| + */ | |
| + protected void doUidlRequest(final String uri, final JSONObject payload, | |
| + final boolean retry) { | |
| RequestCallback requestCallback = new RequestCallback() { | |
| @Override | |
| public void onError(Request request, Throwable exception) { | |
| @@ -887,15 +888,29 @@ | |
| switch (statusCode) { | |
| case 0: | |
| - if (retryCanceledActiveRequest) { | |
| + if (retry) { | |
| /* | |
| - * Request was most likely canceled because the browser | |
| - * is maybe navigating away from the page. Just send the | |
| - * request again without displaying any error in case | |
| - * the navigation isn't carried through. | |
| + * There are 2 situations where the error can pop up: | |
| + * | |
| + * 1) Request was most likely canceled because the | |
| + * browser is maybe navigating away from the page. Just | |
| + * send the request again without displaying any error | |
| + * in case the navigation isn't carried through. | |
| + * | |
| + * 2) The browser failed to establish a network | |
| + * connection. This was observed with keep-alive | |
| + * requests, and under wi-fi roaming conditions. | |
| + * | |
| + * Status code 0 does indicate that there was no server | |
| + * side processing, so we can retry the request. | |
| */ | |
| - retryCanceledActiveRequest = false; | |
| - doUidlRequest(uri, payload); | |
| + VConsole.log("Status code 0, retrying"); | |
| + (new Timer() { | |
| + @Override | |
| + public void run() { | |
| + doUidlRequest(uri, payload, false); | |
| + } | |
| + }).schedule(100); | |
| } else { | |
| handleCommunicationError( | |
| "Invalid status code 0 (server down?)", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment