最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

使用JS传递对象会在节点中引发新错误

IT培训 admin 4浏览 0评论

使用JS传递对象会在节点中引发新错误

我想按如下方式在节点应用程序中引发错误。

throw new Error({ status: 400, error: 'Email already exists' });

这给我以下输出。

Error: [object Object]

我无法访问此错误对象的属性。我在这里错了吗?

回答如下:

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

Error对象将字符串参数作为第一个参数。

JSON.stringify对象,如果您希望将其打印到控制台。

throw new Error(JSON.stringify({ status: 400, error: 'Email already exists' }));

您将获得如下内容:未捕获的错误:{“状态”:400,“错误”:“电子邮件已经存在”}

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

使用JS传递对象会在节点中引发新错误

我想按如下方式在节点应用程序中引发错误。

throw new Error({ status: 400, error: 'Email already exists' });

这给我以下输出。

Error: [object Object]

我无法访问此错误对象的属性。我在这里错了吗?

回答如下:

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

Error对象将字符串参数作为第一个参数。

JSON.stringify对象,如果您希望将其打印到控制台。

throw new Error(JSON.stringify({ status: 400, error: 'Email already exists' }));

您将获得如下内容:未捕获的错误:{“状态”:400,“错误”:“电子邮件已经存在”}

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

发布评论

评论列表 (0)

  1. 暂无评论