Videojs custom error message when error code is 401

2.6k Views Asked by At

I am using videojs . It is self hosted and to get video it is making http hit. There is authentication I have put which which goes with the src. The status code I am getting is 401. How can I print user understandable error message .

Currently I am getting "video could not be loaded, either because the server or network failed or because the format is not supported." . But i want to display error as per status code.

Need Assistance .

Thanks in advance

1

There are 1 best solutions below

0
On

You could try using an xmlhttp head request (after a video error) to capture a specific http status code...

function getError(url, callback)
{
  var xhr = new XMLHttpRequest();
  xhr.open('HEAD', url);
  xhr.onreadystatechange = function() {
    if (this.readyState == this.DONE) {
      callback(this.status);
    }
  };
  xhr.send();
}

/* after your video throws an error, try a simple head request */ 
getError("https://your.domain.com/video/sample.mp4", function(status)     {
  /* handle specific codes here... */ 
  console.log(status);
});