Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
How to detect 401 error when loading video src?

I currently use following, but event reveals little about error.

const video = document.getElementById("video")
const source = video.getAttribute("data-source")
video.src = source;
video.addEventListener("error", (event) => {
    console.log("BOOM")
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

"...But event reveals little about error."

Well you did put console.log("BOOM") as the response. It was never gonna be informative.

You want to detect Error type of either: MEDIA_ERR_NETWORK or MEDIA_ERR_SRC_NOT_SUPPORTED.

Try something like this:

video.addEventListener("error", (event) => { handle_Media_Errors (event) } );

function handle_Media_Errors (evt) 
{
    //# code credits: https://gist.github.com/wilmoore/3252894
    //# video playback failed - show a message saying why...
    switch (evt.target.error.code) 
    {
        case evt.target.error.MEDIA_ERR_DECODE:
        console.log('Media Error ::: The video could not be decoded.');
        break;
        
        case evt.target.error.MEDIA_ERR_ABORTED:
        console.log('Media Error ::: video playback was aborted.');
        break;
        
        case evt.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
        console.log('Media Error ::: The video could not be loaded or its format is not supported.');
        break;
            
        case evt.target.error.MEDIA_ERR_NETWORK:
        console.log('Media Error ::: Video download failed due to a network error');
        break;
        
        default:
        console.log('Media Error ::: An unknown error with your media file has occurred.');
        break;
    }
    
    
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!