@ginger.io/beyonce
Advanced tools
Comparing version 0.0.62 to 0.0.63
@@ -34,3 +34,29 @@ "use strict"; | ||
})); | ||
yield client.transactWrite({ TransactItems: requests }).promise(); | ||
const response = client.transactWrite({ TransactItems: requests }); | ||
// If a transaction is cancelled (i.e. fails), the AWS sdk sticks the reasons in the response | ||
// body, but not the exception. So when errors occur, we extract the reasons (if present) | ||
// See: https://github.com/aws/aws-sdk-js/issues/2464#issuecomment-503524701 | ||
let transactionCancellationReasons; | ||
response.on("extractError", ({ error, httpResponse }) => { | ||
try { | ||
if (error) { | ||
const { CancellationReasons } = JSON.parse(httpResponse.body.toString()); | ||
if (CancellationReasons) { | ||
transactionCancellationReasons = CancellationReasons; | ||
} | ||
} | ||
} | ||
catch (e) { } // no op | ||
}); | ||
try { | ||
yield response.promise(); | ||
} | ||
catch (e) { | ||
if (transactionCancellationReasons) { | ||
throw new Error(`${e.message}. Cancellation Reasons: ${JSON.stringify(transactionCancellationReasons)}`); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
}); | ||
@@ -37,0 +63,0 @@ } |
{ | ||
"name": "@ginger.io/beyonce", | ||
"version": "0.0.62", | ||
"version": "0.0.63", | ||
"description": "Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -36,3 +36,28 @@ import { DynamoDB } from "aws-sdk" | ||
await client.transactWrite({ TransactItems: requests }).promise() | ||
const response = client.transactWrite({ TransactItems: requests }) | ||
// If a transaction is cancelled (i.e. fails), the AWS sdk sticks the reasons in the response | ||
// body, but not the exception. So when errors occur, we extract the reasons (if present) | ||
// See: https://github.com/aws/aws-sdk-js/issues/2464#issuecomment-503524701 | ||
let transactionCancellationReasons: any[] | undefined | ||
response.on("extractError", ({ error, httpResponse }) => { | ||
try { | ||
if (error) { | ||
const { CancellationReasons } = JSON.parse(httpResponse.body.toString()) | ||
if (CancellationReasons) { | ||
transactionCancellationReasons = CancellationReasons | ||
} | ||
} | ||
} catch (e) {} // no op | ||
}) | ||
try { | ||
await response.promise() | ||
} catch (e) { | ||
if (transactionCancellationReasons) { | ||
throw new Error(`${e.message}. Cancellation Reasons: ${JSON.stringify(transactionCancellationReasons)}`) | ||
} else { | ||
throw e | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
358461
5981