mirror of
https://github.com/androidx/media.git
synced 2025-05-07 15:40:37 +08:00
Update OkHttpDataSource with response body on bad HTTP status
This change supplies the response body in OkHttpDataSource to InvalidResponseCodeException. Issue #6853
This commit is contained in:
parent
d94a40ac77
commit
78740bcac6
@ -230,10 +230,19 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
||||
|
||||
// Check for a valid response code.
|
||||
if (!response.isSuccessful()) {
|
||||
byte[] errorResponseBody;
|
||||
try {
|
||||
errorResponseBody = Util.toByteArray(responseByteStream);
|
||||
} catch (IOException e) {
|
||||
throw new HttpDataSourceException(
|
||||
"Error reading response body of unsuccessful response " + dataSpec.uri,
|
||||
e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||
}
|
||||
Map<String, List<String>> headers = response.headers().toMultimap();
|
||||
closeConnectionQuietly();
|
||||
InvalidResponseCodeException exception =
|
||||
new InvalidResponseCodeException(responseCode, response.message(), headers, dataSpec);
|
||||
new InvalidResponseCodeException(responseCode, response.message(), headers, dataSpec,
|
||||
errorResponseBody);
|
||||
if (responseCode == 416) {
|
||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user