mirror of
https://github.com/etesync/android
synced 2024-12-22 22:58:29 +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:
parent
8e7d363128
commit
ba789da797
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
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:
|
||||
throw new Exceptions.HttpException(response);
|
||||
// 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)
|
||||
|
@ -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) {
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user