Commit 9246fbbe by Oliver Woodman

Add exception type for manifest load errors.

parent f3113e70
...@@ -49,6 +49,14 @@ import java.util.concurrent.CancellationException; ...@@ -49,6 +49,14 @@ import java.util.concurrent.CancellationException;
public class ManifestFetcher<T> implements Loader.Callback { public class ManifestFetcher<T> implements Loader.Callback {
/** /**
* Thrown when an error occurs trying to fetch a manifest.
*/
public static final class ManifestIOException extends IOException{
public ManifestIOException(Throwable cause) { super(cause); }
}
/**
* Interface definition for a callback to be notified of {@link ManifestFetcher} events. * Interface definition for a callback to be notified of {@link ManifestFetcher} events.
*/ */
public interface EventListener { public interface EventListener {
...@@ -112,7 +120,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -112,7 +120,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
private int loadExceptionCount; private int loadExceptionCount;
private long loadExceptionTimestamp; private long loadExceptionTimestamp;
private IOException loadException; private ManifestIOException loadException;
private volatile T manifest; private volatile T manifest;
private volatile long manifestLoadStartTimestamp; private volatile long manifestLoadStartTimestamp;
...@@ -201,9 +209,10 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -201,9 +209,10 @@ public class ManifestFetcher<T> implements Loader.Callback {
* Throws the error that affected the most recent attempt to load the manifest. Does nothing if * Throws the error that affected the most recent attempt to load the manifest. Does nothing if
* the most recent attempt was successful. * the most recent attempt was successful.
* *
* @throws IOException The error that affected the most recent attempt to load the manifest. * @throws ManifestIOException The error that affected the most recent attempt to load the
* manifest.
*/ */
public void maybeThrowError() throws IOException { public void maybeThrowError() throws ManifestIOException {
// Don't throw an exception until at least 1 retry attempt has been made. // Don't throw an exception until at least 1 retry attempt has been made.
if (loadException == null || loadExceptionCount <= 1) { if (loadException == null || loadExceptionCount <= 1) {
return; return;
...@@ -291,7 +300,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -291,7 +300,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
loadExceptionCount++; loadExceptionCount++;
loadExceptionTimestamp = SystemClock.elapsedRealtime(); loadExceptionTimestamp = SystemClock.elapsedRealtime();
loadException = new IOException(exception); loadException = new ManifestIOException(exception);
notifyManifestError(loadException); notifyManifestError(loadException);
} }
...@@ -376,7 +385,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -376,7 +385,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
public void onLoadCanceled(Loadable loadable) { public void onLoadCanceled(Loadable loadable) {
// This shouldn't ever happen, but handle it anyway. // This shouldn't ever happen, but handle it anyway.
try { try {
IOException exception = new IOException("Load cancelled", new CancellationException()); IOException exception = new ManifestIOException(new CancellationException());
wrappedCallback.onSingleManifestError(exception); wrappedCallback.onSingleManifestError(exception);
} finally { } finally {
releaseLoader(); releaseLoader();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment