Skip to content

Commit b1f78c3

Browse files
committed
Prevent returning a full object when that object exceeds the max DDB size, because it will get passed to the caller and that will cause unnecessary extra complexity for the caller.
1 parent b0b22ca commit b1f78c3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/dynamoDbSafe.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ class DynamoDB extends DynamoDbOriginal.DocumentClient {
116116
const capturedStack = { name: 'DynamoDB.update() Error:' };
117117
Error.captureStackTrace(capturedStack);
118118
const resultAsync = super.put(params).promise().catch(error => {
119-
const wrappedError = new DynamoDbError({ message: error.message, method: 'Put', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
119+
// Do not log items that are too bit, it will just become a huge problem for the caller.
120+
const loggedParameters = error.code === 'ValidationException' && error.message === 'Item size has exceeded the maximum allowed size'
121+
? { calculatedItemSize: JSON.stringify(originalParams).length }
122+
: originalParams
123+
124+
const wrappedError = new DynamoDbError({ message: error.message, method: 'Put', parameters: loggedParameters, dynamoDbStack: error.stack }, error.code);
120125
wrappedError.stack = capturedStack;
121126
throw wrappedError;
122127
});
@@ -159,7 +164,12 @@ class DynamoDB extends DynamoDbOriginal.DocumentClient {
159164
const capturedStack = { name: 'DynamoDB.update() Error:' };
160165
Error.captureStackTrace(capturedStack);
161166
const resultAsync = super.update(params).promise().catch(error => {
162-
const wrappedError = new DynamoDbError({ message: error.message, method: 'Update', parameters: originalParams, dynamoDbStack: error.stack }, error.code);
167+
// Do not log items that are too bit, it will just become a huge problem for the caller.
168+
const loggedParameters = error.code === 'ValidationException' && error.message === 'Item size has exceeded the maximum allowed size'
169+
? { calculatedItemSize: JSON.stringify(originalParams).length }
170+
: originalParams
171+
172+
const wrappedError = new DynamoDbError({ message: error.message, method: 'Update', parameters: loggedParameters, dynamoDbStack: error.stack }, error.code);
163173
wrappedError.stack = capturedStack;
164174
throw wrappedError;
165175
});

0 commit comments

Comments
 (0)