summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/StopRequestException.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/downloads/StopRequestException.java')
-rw-r--r--src/com/android/providers/downloads/StopRequestException.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/com/android/providers/downloads/StopRequestException.java b/src/com/android/providers/downloads/StopRequestException.java
index 0ccf53cb..a2b642d8 100644
--- a/src/com/android/providers/downloads/StopRequestException.java
+++ b/src/com/android/providers/downloads/StopRequestException.java
@@ -15,6 +15,9 @@
*/
package com.android.providers.downloads;
+import static android.provider.Downloads.Impl.STATUS_UNHANDLED_HTTP_CODE;
+import static android.provider.Downloads.Impl.STATUS_UNHANDLED_REDIRECT;
+
/**
* Raised to indicate that the current request should be stopped immediately.
*
@@ -23,15 +26,36 @@ package com.android.providers.downloads;
* URI, headers, or destination filename.
*/
class StopRequestException extends Exception {
- public int mFinalStatus;
+ private final int mFinalStatus;
public StopRequestException(int finalStatus, String message) {
super(message);
mFinalStatus = finalStatus;
}
- public StopRequestException(int finalStatus, String message, Throwable throwable) {
- super(message, throwable);
+ public StopRequestException(int finalStatus, Throwable t) {
+ super(t);
+ mFinalStatus = finalStatus;
+ }
+
+ public StopRequestException(int finalStatus, String message, Throwable t) {
+ super(message, t);
mFinalStatus = finalStatus;
}
+
+ public int getFinalStatus() {
+ return mFinalStatus;
+ }
+
+ public static StopRequestException throwUnhandledHttpError(int code, String message)
+ throws StopRequestException {
+ final String error = "Unhandled HTTP response: " + code + " " + message;
+ if (code >= 400 && code < 600) {
+ throw new StopRequestException(code, error);
+ } else if (code >= 300 && code < 400) {
+ throw new StopRequestException(STATUS_UNHANDLED_REDIRECT, error);
+ } else {
+ throw new StopRequestException(STATUS_UNHANDLED_HTTP_CODE, error);
+ }
+ }
}