Skip to content

Usage parity of HTTP_ERROR in networking plugins #1519

Closed
@chrisfillmore

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    flag: good first issueThis might be a relatively easy issue; good for new contributorsflag: seeking PRWe are actively seeking PRs for this; we do not currently expect the core team will resolve thisstatus: archivedArchived and locked; will not be updatedtype: enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions