Search code examples
javascriptvideo.js

Videojs how to get ErrorCode?


I am currently trying to get the error code from a Video.js error. I know how to get the error Message but I can't figure out how to get the numeric code for the error.


Solution

  • According to the documentation for MediaError there is a status property which is an array (at the bottom of the page). So it could contain multiple codes.

    status: Array

    An optional status code that can be set by plugins to allow even more detail about the error. For example a plugin might provide a specific HTTP status code and an error message for that code. Then when the plugin gets that error this class will know how to display an error message for it. This allows a custom message to show up on the Player error overlay.

    So there's no guarantee there will even be a status code, the status array could be empty. However, you can check the length of the array to see if there are entries, then loop over them looking to see if they contain the status code(s) you're concerned with.