javascript - 如何在 Node.js 中实例化一个新的 SystemError 对象?
问题描述
查看 Node 的文档,SystemError
扩展Error
类。但是,如果你尝试SystemError
直接使用,Node 会抛出一个未定义的ReferenceError
说法。SystemError
显然,根据文档,可能会遇到 的实例SystemError
,但似乎不可能以通常的方式重新创建这样的错误(例如throw new SystemError(args)
)。
我想测试一些旨在与SystemError
文档中详述的指定 API 交互的代码,但我不知道如何重新创建SystemError
. 这甚至可能吗?
解决方案
我认为 node.js 不可SystemError
用是为了避免任何人(npm 包)使用它。所以 aSystemError
真的是 aSystemError
而不是别的东西。
如果要对其进行测试,请生成错误:例如,尝试读取不存在的文件。
另一个解决方案是重新创建一个相似的错误,因为您知道它的每个属性。但实际上这是一种解决方法。
https://nodejs.org/api/errors.html#errors_class_systemerror
在 Github https://github.com/DefinitelyTyped/DefinitelyTyped我找不到任何.interface
SystemError
除了由node-fetch
,voximplant-websdk
和alexa-sdk
.
https://github.com/DefinitelyTyped/DefinitelyTyped/search?q=systemError&unscoped_q=systemError
推荐阅读
- jenkins - Jenkins 摘要显示插件的问题
- flutter - 如何让细胞的整个区域都感知到触摸?
- react-native - 对齐输入文本以从左侧开始,如占位符文本
- java - Java Spring-BOOT:HTTP处理程序旁边的主循环
- azure-iot-hub - Azure IoT 中心令牌格式和选项
- javers - Javers 不保留错误的布尔值
- flutter - 底部导航栏,每个选项卡都有子导航器
- html - 错误的样式颜色可视化但仅在真实的移动设备上
- python - 如何从 Google Drive 下载多个文本文件并附加到 Pandas 数据框?
- vue.js - 如何在 vue 中使用 grpc-web?