database-connector 2.5.12 → 2.5.13

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.
Files changed (2) hide show
  1. package/models/index.js +9 -1
  2. package/package.json +1 -1
package/models/index.js CHANGED
@@ -29,7 +29,15 @@ const withTransaction = async (fn) => {
29
29
  await session.commitTransaction();
30
30
  return result;
31
31
  } catch (err) {
32
- await session.abortTransaction();
32
+ if (session.inTransaction()) {
33
+ try {
34
+ await session.abortTransaction();
35
+ } catch (abortErr) {
36
+ // Preserve original error while still surfacing abort failure details
37
+ abortErr.originalError = err;
38
+ throw abortErr;
39
+ }
40
+ }
33
41
  throw err;
34
42
  } finally {
35
43
  session.endSession();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.5.12",
3
+ "version": "2.5.13",
4
4
  "description": "MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.",
5
5
  "main": "models/index.js",
6
6
  "scripts": {