Assign CronetDataSource error codes
PiperOrigin-RevId: 387301144
This commit is contained in:
parent
9c27cfcda7
commit
5bc1c4837f
@ -669,11 +669,12 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
if (message != null && Ascii.toLowerCase(message).contains("err_cleartext_not_permitted")) {
|
if (message != null && Ascii.toLowerCase(message).contains("err_cleartext_not_permitted")) {
|
||||||
throw new CleartextNotPermittedException(connectionOpenException, dataSpec);
|
throw new CleartextNotPermittedException(connectionOpenException, dataSpec);
|
||||||
}
|
}
|
||||||
|
@PlaybackException.ErrorCode
|
||||||
|
int errorCode =
|
||||||
|
getErrorCodeForException(
|
||||||
|
connectionOpenException, /* occurredWhileOpeningConnection*/ true);
|
||||||
throw new OpenException(
|
throw new OpenException(
|
||||||
connectionOpenException,
|
connectionOpenException, dataSpec, errorCode, getStatus(urlRequest));
|
||||||
dataSpec,
|
|
||||||
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
|
|
||||||
getStatus(urlRequest));
|
|
||||||
} else if (!connectionOpened) {
|
} else if (!connectionOpened) {
|
||||||
// The timeout was reached before the connection was opened.
|
// The timeout was reached before the connection was opened.
|
||||||
throw new OpenException(
|
throw new OpenException(
|
||||||
@ -1026,7 +1027,10 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
throw (HttpDataSourceException) e;
|
throw (HttpDataSourceException) e;
|
||||||
} else {
|
} else {
|
||||||
throw new OpenException(
|
throw new OpenException(
|
||||||
e, dataSpec, PlaybackException.ERROR_CODE_IO_UNSPECIFIED, Status.READING_RESPONSE);
|
e,
|
||||||
|
dataSpec,
|
||||||
|
getErrorCodeForException(e, /* occurredWhileOpeningConnection= */ false),
|
||||||
|
Status.READING_RESPONSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1098,9 +1102,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
throw new HttpDataSourceException(
|
throw new HttpDataSourceException(
|
||||||
exception,
|
exception,
|
||||||
dataSpec,
|
dataSpec,
|
||||||
exception instanceof UnknownHostException
|
getErrorCodeForException(exception, /* occurredWhileOpeningConnection= */ false),
|
||||||
? PlaybackException.ERROR_CODE_IO_DNS_FAILED
|
|
||||||
: PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
|
|
||||||
HttpDataSourceException.TYPE_READ);
|
HttpDataSourceException.TYPE_READ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1114,6 +1116,25 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
return readBuffer;
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PlaybackException.ErrorCode
|
||||||
|
private static int getErrorCodeForException(
|
||||||
|
IOException exception, boolean occurredWhileOpeningConnection) {
|
||||||
|
if (exception instanceof UnknownHostException) {
|
||||||
|
return PlaybackException.ERROR_CODE_IO_DNS_FAILED;
|
||||||
|
}
|
||||||
|
@Nullable String message = exception.getMessage();
|
||||||
|
if (message != null) {
|
||||||
|
if (message.contains("net::ERR_INTERNET_DISCONNECTED")) {
|
||||||
|
return PlaybackException.ERROR_CODE_IO_NETWORK_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (occurredWhileOpeningConnection) {
|
||||||
|
return PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED;
|
||||||
|
} else {
|
||||||
|
return PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_CLOSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isCompressed(UrlResponseInfo info) {
|
private static boolean isCompressed(UrlResponseInfo info) {
|
||||||
for (Map.Entry<String, String> entry : info.getAllHeadersAsList()) {
|
for (Map.Entry<String, String> entry : info.getAllHeadersAsList()) {
|
||||||
if (entry.getKey().equalsIgnoreCase("Content-Encoding")) {
|
if (entry.getKey().equalsIgnoreCase("Content-Encoding")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user