[media-and-entertainment] [Proposal] Require a httpCode for MediaError (#23)

ysbcc has just created a new issue for https://github.com/w3c/media-and-entertainment:

== [Proposal] Require a httpCode for MediaError ==
**Problem**
When a video error occur, we can get the error code through MediaError. The code defines [here](https://developer.mozilla.org/en-US/docs/Web/API/MediaError):

interface MediaError {
  const unsigned short MEDIA_ERR_ABORTED = 1;
  const unsigned short MEDIA_ERR_NETWORK = 2;
  const unsigned short MEDIA_ERR_DECODE = 3;
  const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  readonly attribute unsigned short code;
};

The problem is, when it comes to **MEDIA_ERR_SRC_NOT_SUPPORTED**, developer can't confirm what had happened. It could be one of the following issues:

1. The src request returned a 403, 403 or 5xx.
2. The src request returned a 200, but it's a html page instead of video. Most likely the request has been blocked.
3. The src request returned a video but the encode was not supported.
4. Other exceptions.

In these cases the "error.message" is empty or just "Format error", no further information.

**Proposed API: a httpCode on MediaError**
We propose an addition attribute, httpCode, on MediaError. So developers can figure out what happened and report the issue. Here's a example:

```
let video = document.createElement('video');
video.addEventListener('error', function() {
    console.log(this.error.httpCode);
}
```

**Other consideration**
By getting the httpCode, we need to follow the CORS specification. Only When the request pass the CORS successfully(or in the same domain), it's allowed to read the httpCode, otherwise throw an exception.
Besides video element, audio can share the httpCode too.

Please view or discuss this issue at https://github.com/w3c/media-and-entertainment/issues/23 using your GitHub account

Received on Wednesday, 17 July 2019 02:40:54 UTC