0
0
DynamoDBquery~10 mins

Error handling and retries in DynamoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to catch a DynamoDB exception.

DynamoDB
try {
  // some DynamoDB operation
} catch ([1] e) {
  console.log('Error:', e.message);
}
Drag options to blanks, or click blank then click option'
AError
BException
CDynamoDBError
DDynamoDBException
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent error class like DynamoDBException.
Using Exception which is not a JavaScript error type.
2fill in blank
medium

Complete the code to retry a DynamoDB operation after catching a throttling error.

DynamoDB
if (error.code === [1]) {
  // retry logic here
}
Drag options to blanks, or click blank then click option'
A"InternalServerError"
B"ProvisionedThroughputExceededException"
C"ResourceNotFoundException"
D"ThrottlingException"
Attempts:
3 left
💡 Hint
Common Mistakes
Using ProvisionedThroughputExceededException which is older and less common.
Using unrelated error codes like ResourceNotFoundException.
3fill in blank
hard

Fix the error in the retry logic to wait before retrying.

DynamoDB
async function retryOperation() {
  try {
    await dynamoDbClient.send(command);
  } catch (error) {
    if (error.code === 'ThrottlingException') {
      await new Promise(resolve => setTimeout([1]));
      return retryOperation();
    }
    throw error;
  }
}
Drag options to blanks, or click blank then click option'
A() => resolve(), 1000
Bresolve, 1000
C() => resolve(), 1000)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing resolve directly without wrapping in a function.
Missing parentheses or commas in setTimeout arguments.
4fill in blank
hard

Fill both blanks to implement exponential backoff in retry delay.

DynamoDB
async function retryWithBackoff(attempt) {
  try {
    await dynamoDbClient.send(command);
  } catch (error) {
    if (error.code === 'ThrottlingException' && attempt < 5) {
      const delay = [1] * Math.pow(2, [2]);
      await new Promise(resolve => setTimeout(() => resolve(), delay));
      return retryWithBackoff(attempt + 1);
    }
    throw error;
  }
}
Drag options to blanks, or click blank then click option'
A100
Battempt
C1000
Dattempt - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large base delay causing long waits.
Using attempt - 1 which delays less on retries.
5fill in blank
hard

Fill all three blanks to log error details and retry with a max attempt limit.

DynamoDB
async function safeRetry(attempt) {
  try {
    await dynamoDbClient.send(command);
  } catch (error) {
    console.error('Error code:', [1]);
    console.error('Error message:', [2]);
    if (error.code === 'ThrottlingException' && [3] < 3) {
      await new Promise(resolve => setTimeout(() => resolve(), 200));
      return safeRetry(attempt + 1);
    }
    throw error;
  }
}
Drag options to blanks, or click blank then click option'
Aerror.code
Berror.message
Cattempt
Derror.statusCode
Attempts:
3 left
💡 Hint
Common Mistakes
Logging wrong error properties like statusCode.
Using a wrong variable for retry count.