where to find all the exception classes in AWS-SDK for dynamodb in NodeJS typescript?

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.

This is what I was trying to do.

// 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')
  }
}

Udpate: aws-sdk v3

Since version v3 the property name has changed to name:

if (e.name === 'ConditionalCheckFailedException') {

Old post: aws-sdk v2

You can check the error by using the following guard instead:

if (e.code === 'ConditionalCheckFailedException') {

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.


When you are using aws-sdk v3 the error does not have a property code. Instead, you want to check error.name.

For example:

import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';

const key = 'myKey.json';
const s3Client = new S3Client({});
const command = new GetObjectCommand({
    Bucket: 'bucketName',
    Key: key
});

try {
    const response = await s3Client.send(command);
} catch (error) {
    if (error.name === 'NoSuchKey') {
        console.warning(`My key="${key}" was not found.`);
    } else {
        throw error;
    }
}