Make HttpDataSourceException use PlaybackException error codes.

PiperOrigin-RevId: 382710409
This commit is contained in:
claincly 2021-07-02 12:04:03 +01:00 committed by kim-vde
parent 747b0f057b
commit 6035932fa3
2 changed files with 115 additions and 12 deletions

View File

@ -52,6 +52,7 @@ public class PlaybackException extends Exception implements Bundleable {
ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT,
ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED,
ERROR_CODE_IO_BAD_HTTP_REQUEST,
ERROR_CODE_IO_BAD_HTTP_STATUS,
ERROR_CODE_IO_DNS_FAILED,
ERROR_CODE_IO_FILE_NOT_FOUND,
@ -106,17 +107,19 @@ public class PlaybackException extends Exception implements Bundleable {
public static final int ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT = 2003;
/** Caused by an existing connection being unexpectedly closed. */
public static final int ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED = 2004;
/** Caused by creating a malformed HTTP request. */
public static final int ERROR_CODE_IO_BAD_HTTP_REQUEST = 2005;
/** Caused by an HTTP server returning an unexpected HTTP response status code. */
public static final int ERROR_CODE_IO_BAD_HTTP_STATUS = 2005;
public static final int ERROR_CODE_IO_BAD_HTTP_STATUS = 2006;
/** Caused by the player failing to resolve a hostname. */
public static final int ERROR_CODE_IO_DNS_FAILED = 2006;
public static final int ERROR_CODE_IO_DNS_FAILED = 2007;
/** Caused by a non-existent file. */
public static final int ERROR_CODE_IO_FILE_NOT_FOUND = 2007;
public static final int ERROR_CODE_IO_FILE_NOT_FOUND = 2008;
/**
* Caused by lack of permission to perform an IO operation. For example, lack of permission to
* access internet or external storage.
*/
public static final int ERROR_CODE_IO_NO_PERMISSION = 2008;
public static final int ERROR_CODE_IO_NO_PERMISSION = 2009;
/**
* Caused by the player trying to access cleartext HTTP traffic (meaning http:// rather than
* https://) when the app's Network Security Configuration does not permit it.
@ -124,9 +127,9 @@ public class PlaybackException extends Exception implements Bundleable {
* <p>See <a href="https://exoplayer.dev/issues/cleartext-not-permitted">this corresponding
* troubleshooting topic</a>.
*/
public static final int ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED = 2009;
public static final int ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED = 2010;
/** Caused by reading data out of the data bound. */
public static final int ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE = 2010;
public static final int ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE = 2011;
// Content parsing errors (3xxx).
@ -217,6 +220,8 @@ public class PlaybackException extends Exception implements Bundleable {
return "ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT";
case ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED:
return "ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED";
case ERROR_CODE_IO_BAD_HTTP_REQUEST:
return "ERROR_CODE_IO_BAD_HTTP_REQUEST";
case ERROR_CODE_IO_BAD_HTTP_STATUS:
return "ERROR_CODE_IO_BAD_HTTP_STATUS";
case ERROR_CODE_IO_DNS_FAILED:

View File

@ -190,24 +190,113 @@ public interface HttpDataSource extends DataSource {
/** The {@link DataSpec} associated with the current connection. */
public final DataSpec dataSpec;
/**
* @deprecated Use {@link #HttpDataSourceException(DataSpec, int, int)
* HttpDataSourceException(DataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, int)}.
*/
@Deprecated
public HttpDataSourceException(DataSpec dataSpec, @Type int type) {
super(PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
this(dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
}
/**
* Constructs an HttpDataSourceException.
*
* @param dataSpec The {@link DataSpec}.
* @param errorCode Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
* PlaybackException.ErrorCode}.
* @param type See {@link Type}.
*/
public HttpDataSourceException(
DataSpec dataSpec, @PlaybackException.ErrorCode int errorCode, @Type int type) {
super(errorCode, type);
this.dataSpec = dataSpec;
}
/**
* @deprecated Use {@link #HttpDataSourceException(String, DataSpec, int, int)
* HttpDataSourceException(String, DataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
* int)}.
*/
@Deprecated
public HttpDataSourceException(String message, DataSpec dataSpec, @Type int type) {
super(message, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
this(message, dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
}
/**
* Constructs an HttpDataSourceException.
*
* @param message The error message.
* @param dataSpec The {@link DataSpec}.
* @param errorCode Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
* PlaybackException.ErrorCode}.
* @param type See {@link Type}.
*/
public HttpDataSourceException(
String message,
DataSpec dataSpec,
@PlaybackException.ErrorCode int errorCode,
@Type int type) {
super(message, errorCode, type);
this.dataSpec = dataSpec;
}
/**
* @deprecated Use {@link #HttpDataSourceException(IOException, DataSpec, int, int)
* HttpDataSourceException(IOException, DataSpec,
* PlaybackException.ERROR_CODE_IO_UNSPECIFIED, int)}.
*/
@Deprecated
public HttpDataSourceException(IOException cause, DataSpec dataSpec, @Type int type) {
super(cause, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
this(cause, dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
}
/**
* Constructs an HttpDataSourceException.
*
* @param cause The error cause.
* @param dataSpec The {@link DataSpec}.
* @param errorCode Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
* PlaybackException.ErrorCode}.
* @param type See {@link Type}.
*/
public HttpDataSourceException(
IOException cause,
DataSpec dataSpec,
@PlaybackException.ErrorCode int errorCode,
@Type int type) {
super(cause, errorCode, type);
this.dataSpec = dataSpec;
}
/**
* @deprecated Use {@link #HttpDataSourceException(String, IOException, DataSpec, int, int)
* HttpDataSourceException(String, IOException, DataSpec,
* PlaybackException.ERROR_CODE_IO_UNSPECIFIED, int)}.
*/
@Deprecated
public HttpDataSourceException(
String message, IOException cause, DataSpec dataSpec, @Type int type) {
super(message, cause, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
this(message, cause, dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, type);
}
/**
* Constructs an HttpDataSourceException.
*
* @param message The error message.
* @param cause The error cause.
* @param dataSpec The {@link DataSpec}.
* @param errorCode Reason of the error, should be one of the {@code ERROR_CODE_IO_*} in {@link
* PlaybackException.ErrorCode}.
* @param type See {@link Type}.
*/
public HttpDataSourceException(
String message,
IOException cause,
DataSpec dataSpec,
@PlaybackException.ErrorCode int errorCode,
@Type int type) {
super(message, cause, errorCode, type);
this.dataSpec = dataSpec;
}
}
@ -226,6 +315,7 @@ public interface HttpDataSource extends DataSource {
+ " https://exoplayer.dev/issues/cleartext-not-permitted",
cause,
dataSpec,
PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED,
TYPE_OPEN);
}
}
@ -236,7 +326,11 @@ public interface HttpDataSource extends DataSource {
public final String contentType;
public InvalidContentTypeException(String contentType, DataSpec dataSpec) {
super("Invalid content type: " + contentType, dataSpec, TYPE_OPEN);
super(
"Invalid content type: " + contentType,
dataSpec,
PlaybackException.ERROR_CODE_IO_BAD_HTTP_REQUEST,
TYPE_OPEN);
this.contentType = contentType;
}
}
@ -295,7 +389,11 @@ public interface HttpDataSource extends DataSource {
Map<String, List<String>> headerFields,
DataSpec dataSpec,
byte[] responseBody) {
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
super(
"Response code: " + responseCode,
dataSpec,
PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS,
TYPE_OPEN);
this.responseCode = responseCode;
this.responseMessage = responseMessage;
this.headerFields = headerFields;