1
0
mirror of https://github.com/etesync/android synced 2025-01-25 15:10:55 +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) { if (e instanceof Exceptions.UnauthorizedException) {
App.log.log(Level.SEVERE, "Not authorized anymore", e); App.log.log(Level.SEVERE, "Not authorized anymore", e);
messageString = R.string.sync_error_unauthorized; 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) { } else if (e instanceof Exceptions.ServiceUnavailableException) {
App.log.log(Level.SEVERE, "Service unavailable"); App.log.log(Level.SEVERE, "Service unavailable");
messageString = R.string.sync_error_unavailable; messageString = R.string.sync_error_unavailable;
@ -91,6 +94,9 @@ public class NotificationHelper {
Intent detailsIntent; Intent detailsIntent;
if (e instanceof Exceptions.UnauthorizedException) { if (e instanceof Exceptions.UnauthorizedException) {
detailsIntent = new Intent(this, AccountSettingsActivity.class); detailsIntent = new Intent(this, AccountSettingsActivity.class);
} else if (e instanceof Exceptions.UserInactiveException) {
startActivity(new Intent(Intent.ACTION_VIEW, Constants.dashboard));
return;
} else { } else {
detailsIntent = new Intent(this, DebugInfoActivity.class); 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.App;
import com.etesync.syncadapter.GsonHelper; import com.etesync.syncadapter.GsonHelper;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -41,14 +42,28 @@ abstract class BaseManager {
throw new Exceptions.ServiceUnavailableException("Service unavailable", Long.valueOf(response.header("Retry-After", "0"))); 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: case HttpURLConnection.HTTP_FORBIDDEN:
throw new Exceptions.HttpException(response); 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; return response;
} }
static class ApiError {
String detail;
String code;
ApiError() {
}
}
static class Base { static class Base {
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)

View File

@ -2,6 +2,7 @@ package com.etesync.syncadapter.journalmanager;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.net.HttpURLConnection;
import at.bitfire.cert4android.Constants; import at.bitfire.cert4android.Constants;
import okhttp3.Headers; 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 static class ServiceUnavailableException extends HttpException {
public long retryAfter; public long retryAfter;
public ServiceUnavailableException(String message) { public ServiceUnavailableException(String message) {

View File

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