@autofleet/sequelize-utils 5.0.4 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -16,6 +16,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  const sequelize_1 = require("sequelize");
17
17
  const debug_1 = __importDefault(require("debug"));
18
18
  const log = debug_1.default('sequelize-utils');
19
+ const rollbackErrorText = 'rollback has been called on this transaction';
20
+ const abortErrorText = 'Transaction cancelled due to request cancellation';
19
21
  exports.default = (sequelize) => {
20
22
  const transactionWithRetry = (funcToRun, retriesCount = 2) => __awaiter(void 0, void 0, void 0, function* () {
21
23
  try {
@@ -39,8 +41,13 @@ exports.default = (sequelize) => {
39
41
  });
40
42
  // eslint-disable-next-line @typescript-eslint/ban-types
41
43
  const httpBasedTransaction = (req, cb) => transactionWithRetry((transaction) => __awaiter(void 0, void 0, void 0, function* () {
44
+ if (req.aborted) {
45
+ log(abortErrorText);
46
+ throw new Error(abortErrorText);
47
+ }
42
48
  // https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
43
49
  req.on('aborted', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ log(abortErrorText);
44
51
  yield transaction.rollback();
45
52
  }));
46
53
  try {
@@ -48,8 +55,8 @@ exports.default = (sequelize) => {
48
55
  return response;
49
56
  }
50
57
  catch (e) {
51
- if (e.message.includes('rollback has been called on this transaction')) {
52
- throw new Error('Transaction cancelled due to request cancellation');
58
+ if (e.message.includes(rollbackErrorText)) {
59
+ throw new Error(abortErrorText);
53
60
  }
54
61
  throw e;
55
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sequelize-utils",
3
- "version": "5.0.4",
3
+ "version": "5.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -4,6 +4,9 @@ import debug from 'debug';
4
4
 
5
5
  const log = debug('sequelize-utils');
6
6
 
7
+ const rollbackErrorText = 'rollback has been called on this transaction';
8
+ const abortErrorText = 'Transaction cancelled due to request cancellation';
9
+
7
10
  export default (sequelize: Sequelize): {
8
11
  transactionWithRetry: any,
9
12
  httpBasedTransaction: any
@@ -30,16 +33,23 @@ export default (sequelize: Sequelize): {
30
33
 
31
34
  // eslint-disable-next-line @typescript-eslint/ban-types
32
35
  const httpBasedTransaction = (req: any, cb: Function) => transactionWithRetry(async (transaction: Transaction) => {
36
+ if (req.aborted) {
37
+ log(abortErrorText);
38
+ throw new Error(abortErrorText);
39
+ }
40
+
33
41
  // https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/test/parallel/test-http-aborted.js#L9
34
42
  req.on('aborted', async () => {
43
+ log(abortErrorText);
35
44
  await transaction.rollback();
36
45
  });
46
+
37
47
  try {
38
48
  const response = await cb(transaction);
39
49
  return response;
40
50
  } catch (e) {
41
- if (e.message.includes('rollback has been called on this transaction')) {
42
- throw new Error('Transaction cancelled due to request cancellation');
51
+ if (e.message.includes(rollbackErrorText)) {
52
+ throw new Error(abortErrorText);
43
53
  }
44
54
  throw e;
45
55
  }