1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 00:16:09 +00:00

Merge pull request #144 from owncloud/bug_1722_maintenance_mode

Handle 503 code error
This commit is contained in:
David A. Velasco 2017-01-10 18:57:54 +01:00 committed by GitHub
commit 67665b8691
2 changed files with 45 additions and 39 deletions

View File

@ -3,7 +3,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.0' classpath 'com.android.tools.build:gradle:2.2.3'
} }
} }

View File

@ -34,6 +34,7 @@ import java.net.SocketException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountsException; import android.accounts.AccountsException;
@ -61,9 +62,10 @@ import javax.net.ssl.SSLException;
*/ */
public class RemoteOperationResult implements Serializable { public class RemoteOperationResult implements Serializable {
/** Generated - should be refreshed every time the class changes!! */; /** Generated - should be refreshed every time the class changes!! */
private static final long serialVersionUID = 1129130415603799707L; ;
private static final long serialVersionUID = -1909603208238358633L;
private static final String TAG = RemoteOperationResult.class.getSimpleName(); private static final String TAG = RemoteOperationResult.class.getSimpleName();
public enum ResultCode { public enum ResultCode {
@ -100,19 +102,20 @@ public class RemoteOperationResult implements Serializable {
ACCOUNT_NOT_THE_SAME, ACCOUNT_NOT_THE_SAME,
INVALID_CHARACTER_IN_NAME, INVALID_CHARACTER_IN_NAME,
SHARE_NOT_FOUND, SHARE_NOT_FOUND,
LOCAL_STORAGE_NOT_REMOVED, LOCAL_STORAGE_NOT_REMOVED,
FORBIDDEN, FORBIDDEN,
SHARE_FORBIDDEN, SHARE_FORBIDDEN,
OK_REDIRECT_TO_NON_SECURE_CONNECTION, OK_REDIRECT_TO_NON_SECURE_CONNECTION,
INVALID_MOVE_INTO_DESCENDANT, INVALID_MOVE_INTO_DESCENDANT,
INVALID_COPY_INTO_DESCENDANT, INVALID_COPY_INTO_DESCENDANT,
PARTIAL_MOVE_DONE, PARTIAL_MOVE_DONE,
PARTIAL_COPY_DONE, PARTIAL_COPY_DONE,
SHARE_WRONG_PARAMETER, SHARE_WRONG_PARAMETER,
WRONG_SERVER_RESPONSE, WRONG_SERVER_RESPONSE,
INVALID_CHARACTER_DETECT_IN_SERVER, INVALID_CHARACTER_DETECT_IN_SERVER,
DELAYED_FOR_WIFI, DELAYED_FOR_WIFI,
LOCAL_FILE_NOT_FOUND LOCAL_FILE_NOT_FOUND,
MAINTENANCE_MODE
} }
private boolean mSuccess = false; private boolean mSuccess = false;
@ -127,7 +130,7 @@ public class RemoteOperationResult implements Serializable {
public RemoteOperationResult(ResultCode code) { public RemoteOperationResult(ResultCode code) {
mCode = code; mCode = code;
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL ||
code == ResultCode.OK_NO_SSL || code == ResultCode.OK_NO_SSL ||
code == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION); code == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION);
mData = null; mData = null;
@ -142,28 +145,31 @@ public class RemoteOperationResult implements Serializable {
} else if (httpCode > 0) { } else if (httpCode > 0) {
switch (httpCode) { switch (httpCode) {
case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_UNAUTHORIZED:
mCode = ResultCode.UNAUTHORIZED; mCode = ResultCode.UNAUTHORIZED;
break; break;
case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_NOT_FOUND:
mCode = ResultCode.FILE_NOT_FOUND; mCode = ResultCode.FILE_NOT_FOUND;
break; break;
case HttpStatus.SC_INTERNAL_SERVER_ERROR: case HttpStatus.SC_INTERNAL_SERVER_ERROR:
mCode = ResultCode.INSTANCE_NOT_CONFIGURED; mCode = ResultCode.INSTANCE_NOT_CONFIGURED;
break; break;
case HttpStatus.SC_CONFLICT: case HttpStatus.SC_CONFLICT:
mCode = ResultCode.CONFLICT; mCode = ResultCode.CONFLICT;
break; break;
case HttpStatus.SC_INSUFFICIENT_STORAGE: case HttpStatus.SC_INSUFFICIENT_STORAGE:
mCode = ResultCode.QUOTA_EXCEEDED; mCode = ResultCode.QUOTA_EXCEEDED;
break; break;
case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_FORBIDDEN:
mCode = ResultCode.FORBIDDEN; mCode = ResultCode.FORBIDDEN;
break; break;
default: case HttpStatus.SC_SERVICE_UNAVAILABLE:
mCode = ResultCode.UNHANDLED_HTTP_CODE; mCode = ResultCode.MAINTENANCE_MODE;
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + break;
httpCode); default:
mCode = ResultCode.UNHANDLED_HTTP_CODE;
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " +
httpCode);
} }
} }
} }
@ -366,7 +372,7 @@ public class RemoteOperationResult implements Serializable {
} else if (mException instanceof AccountNotFoundException) { } else if (mException instanceof AccountNotFoundException) {
Account failedAccount = Account failedAccount =
((AccountNotFoundException)mException).getFailedAccount(); ((AccountNotFoundException) mException).getFailedAccount();
return mException.getMessage() + " (" + return mException.getMessage() + " (" +
(failedAccount != null ? failedAccount.name : "NULL") + ")"; (failedAccount != null ? failedAccount.name : "NULL") + ")";
@ -403,12 +409,12 @@ public class RemoteOperationResult implements Serializable {
return "Authenticated with a different account than the one updating"; return "Authenticated with a different account than the one updating";
} else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) { } else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) {
return "The file name contains an forbidden character"; return "The file name contains an forbidden character";
} else if (mCode == ResultCode.FILE_NOT_FOUND) { } else if (mCode == ResultCode.FILE_NOT_FOUND) {
return "Local file does not exist"; return "Local file does not exist";
} else if (mCode == ResultCode.SYNC_CONFLICT) { } else if (mCode == ResultCode.SYNC_CONFLICT) {
return "Synchronization conflict"; return "Synchronization conflict";
} }