where to find all the exception classes in AWS-SDK for dynamodb in NodeJS typescript?(在哪里可以找到 AWS-SDK for dynamodb 在 NodeJS 打字稿中的所有异常类?)
问题描述
我正在尝试将一些数据插入 dynamodb,并且正如预期的那样,我得到了一个 ConditionalCheckFailedException
.因此,我试图仅针对该场景捕获该异常,除此之外,我想为所有其他错误引发服务器错误.但是要添加类型,我无法在 aws-sdk 中找到 ConditionalCheckFailedException
.
I am trying to insert some data into dynamodb, and as expected I am getting a ConditionalCheckFailedException
. So I am trying to catch that exception for only that scenario, apart from that I want to throw server error for all other errors.
But to add the type, I am not able to find the ConditionalCheckFailedException
in aws-sdk.
这就是我想要做的.
// where to import this from
try {
await AWS.putItem(params).promise()
} catch (e) {
if (e instanceof ConditionalCheckFailedException) { // unable to find this exception type in AWS SDK
throw new Error('create error')
} else {
throw new Error('server error')
}
}
推荐答案
你可以使用下面的守卫来检查错误:
You can check the error by using the following guard instead:
if (e.code === 'ConditionalCheckFailedException') {
请注意,instanceof
仅适用于类,不适用于接口.所以即使你有类型,如果它是一个接口,你也不能使用它,因为它依赖于某些原型检查.使用 err.code
属性更安全.
Note that instanceof
only works on classes, not on interfaces. So even if you had the type, if it was an interface you couldn't use it because it relies on certain prototype checks. Using the err.code
property is safer.
这篇关于在哪里可以找到 AWS-SDK for dynamodb 在 NodeJS 打字稿中的所有异常类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在哪里可以找到 AWS-SDK for dynamodb 在 NodeJS 打字稿中的所有异常类?


基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01