如何从视频标记错误事件中获取字符串/消息或代码

How can I get the string/message or code from a video tag error event?

本文关键字:字符串 获取 消息 代码 事件 视频 错误      更新时间:2024-02-13

所以这感觉像是一个愚蠢的问题。希望我只是忽略了一些显而易见的东西,但我在听视频元素上的错误。错误字符串实际上显示在控制台中,并且错误事件正确地触发,但当我查看错误对象时,似乎在任何地方都找不到该字符串。我的目标是简单地记录这个错误以用于日志记录。另一种选择是获取错误代码——任何真正可以记录的东西,让我们的调试器了解问题的实质。知道如何从视频标签错误对象中获取错误字符串或代码吗?

代码:

$(this.video)
    .on( 'error', this.proxy(this.onVideoError));
onVideoError : function(e) {
  console.log(e, " the e");
  console.log(e.toString());//prints [object Object]
  console.log(e.code, " the code");// prints undefined
},

在我的错误处理程序中,我使用err.nameerr.message成员。由于错误实际上没有像PHP或其他语言中那样的代码,您可能需要解析消息和名称来创建自己的代码。

var errorHandler = function(err) {
  // prints the name of the error
  console.log(err.name);
  // prints the description that is also shown in the error console
  console.log(err.message);
  // this works only in some browsers
  // line and stack are not supported by all vendors
  console.log(err.line, err.stack);
}