Skip to content

Commit cb64d76

Browse files
committed
Add response text to HTTP errors
Requested in #319 Change-Id: I2f52519d7a45769a0d2db3c038c9c04cf7fb59c1
1 parent 6e4d3b1 commit cb64d76

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/net/http_plugin.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ shaka.net.HttpPlugin = function(uri, request) {
5959
var response = {uri: uri, data: target.response, headers: headers};
6060
resolve(response);
6161
} else {
62-
if (!COMPILED) {
63-
var responseText =
64-
shaka.util.StringUtils.fromBytesAutoDetect(target.response);
65-
shaka.log.debug('HTTP error text:', responseText);
66-
}
62+
var responseText = null;
63+
try {
64+
responseText = shaka.util.StringUtils.fromBytesAutoDetect(
65+
target.response);
66+
} catch (exception) {}
67+
shaka.log.debug('HTTP error text:', responseText);
6768
reject(new shaka.util.Error(
6869
shaka.util.Error.Category.NETWORK,
6970
shaka.util.Error.Code.BAD_HTTP_STATUS,
7071
uri,
71-
target.status));
72+
target.status,
73+
responseText));
7274
}
7375
};
7476
xhr.onerror = function(event) {

lib/util/error.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ shaka.util.Error.Code = {
135135
* An HTTP network request returned an HTTP status that indicated a failure.
136136
* <br> error.data[0] is the URI.
137137
* <br> error.data[1] is the status code.
138+
* <br> error.data[2] is the response text, or null if the response could not
139+
* be interpretted as text.
138140
*/
139141
'BAD_HTTP_STATUS': 1001,
140142

0 commit comments

Comments
 (0)