dynamoose
dynamoose copied to clipboard
[FEATURE] When dynamoose.transaction throws a transaction cancelled exception, include the reasons for cancellation
Summary:
When Dynamo throws a transaction cancelled exception, its HTTP response body includes a list of reasons for cancellation. But the error thrown from the sdk's Promise object does not include these reasons.
So, per: aws/aws-sdk-js#2464 (comment) -- we have to parse them out.
Code sample:
General
This is the exmaple of dynamoose.transaction
exception of any type of errors:
{
"innerData": {
"message": "Transaction cancelled, please refer cancellation reasons for specific reasons [None, ConditionalCheckFailed]",
"code": "TransactionCanceledException",
"time": "2021-05-03T01:28:22.914Z",
"requestId": "E665JME5VFHQK418R949R7QH97VV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 38.27170776979997
},
"innerStackTrace": "TransactionCanceledException: Transaction cancelled, please refer cancellation reasons for specific reasons [None, ConditionalCheckFailed]\n at Request.extractError (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/protocol/json.js:52:27)\n at Request.callListeners (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/sequential_executor.js:106:20)\n at Request.emit (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/sequential_executor.js:78:10)\n at Request.emit (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/request.js:688:14)\n at Request.transition (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/request.js:22:10)\n at AcceptorStateMachine.runTo (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/state_machine.js:14:12)\n at /var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/state_machine.js:26:10\n at Request.<anonymous> (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/request.js:38:9)\n at Request.<anonymous> (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/request.js:690:12)\n at Request.callListeners (/var/task/node_modules/dynamoose/node_modules/aws-sdk/lib/sequential_executor.js:116:18)"
}
The current solution: example of code
Environment:
Operating System: Ubuntu
Operating System Version: 20.04.2
Node.js version (node -v
): 14.16.0
NPM version: (npm -v
): 7.9.0
Dynamoose version: 2.7.3
Other information (if applicable):
Other:
- [x] I have read through the Dynamoose documentation before posting this issue
- [x] I have searched through the GitHub issues (including closed issues) and pull requests to ensure this feature has not already been suggested before
- [x] I have filled out all fields above
- [x] I am running the latest version of Dynamoose