Skip to content

Commit

Permalink
Prevent returning a full object when that object exceeds the max DDB …
Browse files Browse the repository at this point in the history
…size, because it will get passed to the caller and that will cause unnecessary extra complexity for the caller.
  • Loading branch information
wparad committed Nov 27, 2024
1 parent b0b22ca commit b1f78c3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/dynamoDbSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ class DynamoDB extends DynamoDbOriginal.DocumentClient {
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.put(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Put', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
// Do not log items that are too bit, it will just become a huge problem for the caller.
const loggedParameters = error.code === 'ValidationException' && error.message === 'Item size has exceeded the maximum allowed size'
? { calculatedItemSize: JSON.stringify(originalParams).length }
: originalParams

Check failure on line 122 in src/dynamoDbSafe.js

View workflow job for this annotation

GitHub Actions / nodejs

Missing semicolon

const wrappedError = new DynamoDbError({ message: error.message, method: 'Put', parameters: loggedParameters, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
Expand Down Expand Up @@ -159,7 +164,12 @@ class DynamoDB extends DynamoDbOriginal.DocumentClient {
const capturedStack = { name: 'DynamoDB.update() Error:' };
Error.captureStackTrace(capturedStack);
const resultAsync = super.update(params).promise().catch(error => {
const wrappedError = new DynamoDbError({ message: error.message, method: 'Update', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
// Do not log items that are too bit, it will just become a huge problem for the caller.
const loggedParameters = error.code === 'ValidationException' && error.message === 'Item size has exceeded the maximum allowed size'
? { calculatedItemSize: JSON.stringify(originalParams).length }
: originalParams

Check failure on line 170 in src/dynamoDbSafe.js

View workflow job for this annotation

GitHub Actions / nodejs

Missing semicolon

const wrappedError = new DynamoDbError({ message: error.message, method: 'Update', parameters: loggedParameters, dynamoDbStack: error.stack }, error.code);
wrappedError.stack = capturedStack;
throw wrappedError;
});
Expand Down

0 comments on commit b1f78c3

Please sign in to comment.