Skip to content

Commit

Permalink
feat(AWS DynamoDB Node): Improve error handling + add optional GetAll…
Browse files Browse the repository at this point in the history
… Scan FilterExpression (#3318)

* FilterExpression, ExpressionAttributeValues optional

* Returns AWS JSON messages not in response body

* 🔨 fixed filterExpression missing in request body

* ⚡ linter fixes

* Reintroduced 'fix' block at :311 results in duplication

* ⚡ lock file fix

* ⚡ fix

Co-authored-by: Michael Kret <michael.k@radency.com>
  • Loading branch information
ctrl-freak and michael-radency authored Jul 10, 2022
1 parent 82a254a commit 732c8fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 10 additions & 2 deletions packages/nodes-base/nodes/Aws/DynamoDB/AwsDynamoDB.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,13 @@ export class AwsDynamoDB implements INodeType {

const body: IRequestBody = {
TableName: this.getNodeParameter('tableName', i) as string,
ExpressionAttributeValues: adjustExpressionAttributeValues(eavUi),
};

if (scan === true) {
body['FilterExpression'] = this.getNodeParameter('filterExpression', i) as string;
const filterExpression = this.getNodeParameter('filterExpression', i) as string;
if (filterExpression) {
body['FilterExpression'] = filterExpression;
}
} else {
body['KeyConditionExpression'] = this.getNodeParameter('keyConditionExpression', i) as string;
}
Expand All @@ -332,6 +334,12 @@ export class AwsDynamoDB implements INodeType {
body.ExpressionAttributeNames = expressionAttributeName;
}

const expressionAttributeValues = adjustExpressionAttributeValues(eavUi);

if (Object.keys(expressionAttributeValues).length) {
body.ExpressionAttributeValues = expressionAttributeValues;
}

if (indexName) {
body.IndexName = indexName;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Aws/DynamoDB/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I
try {
return JSON.parse(await this.helpers.request!(options));
} catch (error) {
const errorMessage = (error.response && error.response.body.message) || (error.response && error.response.body.Message) || error.message;
const errorMessage = (error.response && error.response.body && error.response.body.message) || (error.response && error.response.body && error.response.body.Message) || error.message;
if (error.statusCode === 403) {
if (errorMessage === 'The security token included in the request is invalid.') {
throw new Error('The AWS credentials are not valid!');
Expand Down
9 changes: 4 additions & 5 deletions packages/nodes-base/nodes/Aws/DynamoDB/ItemDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const itemFields: INodeProperties[] = [
],
},
],
description: 'Item\'s primary key. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key',
description: 'Item\'s primary key. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.',
},
{
displayName: 'Simplify',
Expand Down Expand Up @@ -593,7 +593,7 @@ export const itemFields: INodeProperties[] = [
],
},
],
description: 'Item\'s primary key. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key',
description: 'Item\'s primary key. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.',
},
{
displayName: 'Additional Fields',
Expand Down Expand Up @@ -695,7 +695,6 @@ export const itemFields: INodeProperties[] = [
displayName: 'Filter Expression',
name: 'filterExpression',
type: 'string',
required: true,
displayOptions: {
show: {
scan: [
Expand All @@ -704,7 +703,7 @@ export const itemFields: INodeProperties[] = [
},
},
default: '',
description: 'A filter expression determines which items within the Scan results should be returned to you. All of the other results are discarded.',
description: 'A filter expression determines which items within the Scan results should be returned to you. All of the other results are discarded. Empty value will return all Scan results.',
},
{
displayName: 'Key Condition Expression',
Expand Down Expand Up @@ -912,7 +911,7 @@ export const itemFields: INodeProperties[] = [
name: 'projectionExpression',
type: 'string',
default: '',
description: 'Text that identifies one or more attributes to retrieve from the table. These attributes can include scalars, sets, or elements of a JSON document. The attributes in the expression must be separated by commas',
description: 'Text that identifies one or more attributes to retrieve from the table. These attributes can include scalars, sets, or elements of a JSON document. The attributes in the expression must be separated by commas.',
},
{
displayName: 'Filter Expression',
Expand Down

0 comments on commit 732c8fc

Please sign in to comment.