mirror of
https://github.com/etesync/android
synced 2025-05-08 09:58:51 +00:00
Better handle service unavailable.
This commit is contained in:
parent
3e5f3f5429
commit
a460a52079
@ -37,5 +37,5 @@ public class Constants {
|
|||||||
public static final Uri serviceUrl = Uri.parse((DEBUG_REMOTE_URL == null) ? "https://api.etesync.com/" : DEBUG_REMOTE_URL);
|
public static final Uri serviceUrl = Uri.parse((DEBUG_REMOTE_URL == null) ? "https://api.etesync.com/" : DEBUG_REMOTE_URL);
|
||||||
|
|
||||||
public static final int DEFAULT_SYNC_INTERVAL = 4 * 3600; // 4 hours
|
public static final int DEFAULT_SYNC_INTERVAL = 4 * 3600; // 4 hours
|
||||||
|
public static final long DEFAULT_RETRY_DELAY = 30 * 60; // 30 minutes
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@ abstract class BaseManager {
|
|||||||
|
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
switch (response.code()) {
|
switch (response.code()) {
|
||||||
|
case HttpURLConnection.HTTP_UNAVAILABLE:
|
||||||
|
throw new Exceptions.ServiceUnavailableException("Service unavailable", Long.valueOf(response.header("Retry-After", "0")));
|
||||||
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
||||||
throw new Exceptions.UnauthorizedException("Failed to connect");
|
throw new Exceptions.UnauthorizedException("Failed to connect");
|
||||||
default:
|
default:
|
||||||
|
@ -19,8 +19,13 @@ public class Exceptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ServiceUnavailableException extends HttpException {
|
public static class ServiceUnavailableException extends HttpException {
|
||||||
|
public long retryAfter;
|
||||||
public ServiceUnavailableException(String message) {
|
public ServiceUnavailableException(String message) {
|
||||||
|
this(message, 0);
|
||||||
|
}
|
||||||
|
public ServiceUnavailableException(String message, long retryAfter) {
|
||||||
super(message);
|
super(message);
|
||||||
|
this.retryAfter = retryAfter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import at.bitfire.davdroid.AccountSettings;
|
import at.bitfire.davdroid.AccountSettings;
|
||||||
import at.bitfire.davdroid.App;
|
import at.bitfire.davdroid.App;
|
||||||
|
import at.bitfire.davdroid.Constants;
|
||||||
import at.bitfire.davdroid.GsonHelper;
|
import at.bitfire.davdroid.GsonHelper;
|
||||||
import at.bitfire.davdroid.HttpClient;
|
import at.bitfire.davdroid.HttpClient;
|
||||||
import at.bitfire.davdroid.InvalidAccountException;
|
import at.bitfire.davdroid.InvalidAccountException;
|
||||||
@ -183,11 +184,8 @@ abstract public class SyncManager {
|
|||||||
syncResult.stats.numIoExceptions++;
|
syncResult.stats.numIoExceptions++;
|
||||||
|
|
||||||
} catch (Exceptions.ServiceUnavailableException e) {
|
} catch (Exceptions.ServiceUnavailableException e) {
|
||||||
Date retryAfter = null; // ((Exceptions.ServiceUnavailableException) e).retryAfter;
|
long retryAfter = (e.retryAfter > 0) ? e.retryAfter : Constants.DEFAULT_RETRY_DELAY;
|
||||||
if (retryAfter != null) {
|
syncResult.delayUntil = retryAfter;
|
||||||
// how many seconds to wait? getTime() returns ms, so divide by 1000
|
|
||||||
// syncResult.delayUntil = (retryAfter.getTime() - new Date().getTime()) / 1000;
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return;
|
return;
|
||||||
} catch (Exception | OutOfMemoryError e) {
|
} catch (Exception | OutOfMemoryError e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user