1
0
mirror of https://github.com/etesync/android synced 2024-12-23 07:08:16 +00:00

Add a UserInactive exception for when the user is no longer active

This is a possible error message we get when we get error code 403
(permission denied) from the server. We then handle it explicitly by
sending the user to the dashboard.
This commit is contained in:
Tom Hacohen 2017-02-28 17:37:00 +00:00
parent 8e7d363128
commit ba789da797
4 changed files with 30 additions and 1 deletions

View File

@ -40,6 +40,9 @@ public class NotificationHelper {
if (e instanceof Exceptions.UnauthorizedException) {
App.log.log(Level.SEVERE, "Not authorized anymore", e);
messageString = R.string.sync_error_unauthorized;
} else if (e instanceof Exceptions.UserInactiveException) {
App.log.log(Level.SEVERE, "User inactive");
messageString = R.string.sync_error_user_inactive;
} else if (e instanceof Exceptions.ServiceUnavailableException) {
App.log.log(Level.SEVERE, "Service unavailable");
messageString = R.string.sync_error_unavailable;
@ -91,6 +94,9 @@ public class NotificationHelper {
Intent detailsIntent;
if (e instanceof Exceptions.UnauthorizedException) {
detailsIntent = new Intent(this, AccountSettingsActivity.class);
} else if (e instanceof Exceptions.UserInactiveException) {
startActivity(new Intent(Intent.ACTION_VIEW, Constants.dashboard));
return;
} else {
detailsIntent = new Intent(this, DebugInfoActivity.class);
}

View File

@ -9,6 +9,7 @@ import java.util.logging.Level;
import com.etesync.syncadapter.App;
import com.etesync.syncadapter.GsonHelper;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
@ -41,14 +42,28 @@ abstract class BaseManager {
throw new Exceptions.ServiceUnavailableException("Service unavailable", Long.valueOf(response.header("Retry-After", "0")));
case HttpURLConnection.HTTP_UNAUTHORIZED:
throw new Exceptions.UnauthorizedException("Failed to connect");
default:
throw new Exceptions.HttpException(response);
case HttpURLConnection.HTTP_FORBIDDEN:
ApiError apiError = GsonHelper.gson.fromJson(response.body().charStream(), ApiError.class);
if (apiError.code.equals("service_inactive")) {
throw new Exceptions.UserInactiveException(apiError.detail);
}
default:
// Fall through. We want to always throw when unsuccessful.
}
throw new Exceptions.HttpException(response);
}
return response;
}
static class ApiError {
String detail;
String code;
ApiError() {
}
}
static class Base {
@Setter(AccessLevel.PACKAGE)
@Getter(AccessLevel.PACKAGE)

View File

@ -2,6 +2,7 @@ package com.etesync.syncadapter.journalmanager;
import java.io.IOException;
import java.io.Serializable;
import java.net.HttpURLConnection;
import at.bitfire.cert4android.Constants;
import okhttp3.Headers;
@ -17,6 +18,12 @@ public class Exceptions {
}
}
public static class UserInactiveException extends HttpException {
public UserInactiveException(String message) {
super(HttpURLConnection.HTTP_FORBIDDEN, message);
}
}
public static class ServiceUnavailableException extends HttpException {
public long retryAfter;
public ServiceUnavailableException(String message) {

View File

@ -281,6 +281,7 @@
<string name="sync_phase_push_entries">pushing entries</string>
<string name="sync_phase_post_processing">post processing</string>
<string name="sync_error_unauthorized">Authentication failed</string>
<string name="sync_error_user_inactive">User is inactive</string>
<!-- cert4android -->
<string name="certificate_notification_connection_security">EteSync: Connection security</string>