Description
I believe the usage of 1002 HTTP_ERROR is not exactly comparable between HttpFetchPlugin
and HttpXhrPlugin
. Specifically, I believe this check in HttpFetchPlugin
is not correct:
} else if (error.severity == undefined) {
// Replace non-shaka errors with a generic HTTP_ERROR.
return Promise.reject(new shaka.util.Error(
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.HTTP_ERROR,
uri, error, requestType));
If HttpPluginUtils.makeResponse
(used earlier in the promise chain) threw a ReferenceError due to a typo during development, it would get caught and wrapped in HTTP_ERROR. The same could not happen in HttpXhrPlugin
. I think it is preferable for such an error to escalate immediately and infect your calling code, so that it is caught easily.
Consider this change, to catch fetch
promise rejection immediately:
let promise = fetch(uri, init).catch((error) => {
return Promise.reject(new shaka.util.Error(
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.HTTP_ERROR,
uri, error, requestType));
});
promise = promise.then(function(response) {
...
return shaka.net.HttpPluginUtils.makeResponse(headers,
arrayBuffer, response.status, uri, response.url, requestType);
});
}).catch(function(error) {
goog.asserts.assert(error instanceof shaka.util.Error, 'Wrong error type!');
You would also be able to assert that the error caught at the end of the chain is a shaka.util.Error
, and there would be no fuzzy check for error.severity
.
Do you agree?
Activity