Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Better error handler #365

Open
btzr-io opened this issue Mar 9, 2019 · 0 comments
Open

Better error handler #365

btzr-io opened this issue Mar 9, 2019 · 0 comments

Comments

@btzr-io
Copy link
Owner

btzr-io commented Mar 9, 2019

audioElement.onerror = function() {
    let s = "";
    let err = audioElement.error;
    
    switch(err.code) {
      case MediaError.MEDIA_ERR_ABORTED:
        s += "The user canceled the audio.";
        break;
      case MediaError.MEDIA_ERR_NETWORK:
        s+= "A network error occurred while fetching the audio.";
        break;
      case MediaError.MEDIA_ERR_DECODE:
        s+= "An error occurred while decoding the audio.";
        break;
      case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:
        s+= "The audio is missing or is in a format not supported by your browser.";
        break;
      default:
        s += "An unknown error occurred.";
        break;
    }
    
    let message = err.message;
    
    if (message && message.length) {
      s += " " + message;
    }
    
    displayErrorMessage("<strong>Error " + err.code + ":</strong> " + s + "<br>");
  };

https://developer.mozilla.org/en-US/docs/Web/API/MediaError/message

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant