async function getItems()

in DynamoDB-SDK-Examples/node.js/WorkingWithCustomBackoffRetry/exponential_backoff_retry_get_item.js [10:46]


async function getItems() {
    let retries = 0;
    let condition = true;
    const MAX_RETRY = 7;
    const client = new DynamoDBClient({ region: "us-east-1", maxRetries: 0 });
    const ddbDocClient = DynamoDBDocumentClient.from(client);
    while (condition) {
        try {
            condition = false;
            return await ddbDocClient.send(
                new GetCommand({
                    TableName: "Music",
                    Key: {
                        artist: "batman0", // Partition Key
                        title: "happy0"          // Sort Key
                    },
                    ConsistentRead: false,
                })
            );
        } catch (err) {
            retries += 1;
            backoffTime = (2 ** retries);
            if (!retryNamedExceptions.includes(err.name)){
                console.log("Error has occurred: " + err.name);
                throw err;
            }
            if (retries < MAX_RETRY && retryNamedExceptions.includes(err.name)) {
                return delay(backoffTime);
            }
            else {
                condition = false;
                console.log("Max retry Done or not retriable");
                throw err;
            }
        }
    }
}