mts-booking-library 1.2.19 → 1.2.20

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.
@@ -153,7 +153,7 @@ var JourneyBooking = /** @class */ (function (_super) {
153
153
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
154
154
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
155
155
  localStorage.removeItem("cartId");
156
- throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
156
+ throw new Error(response);
157
157
  }
158
158
  return response.cart;
159
159
  })];
@@ -779,18 +779,27 @@ exports.JourneyBooking = JourneyBooking;
779
779
  return __generator(this, function (_a) {
780
780
  switch (_a.label) {
781
781
  case 0:
782
- _a.trys.push([0, 3, , 4]);
783
782
  booking = new JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
784
- if (!booking.cartId) return [3 /*break*/, 2];
785
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
783
+ _a.label = 1;
786
784
  case 1:
785
+ _a.trys.push([1, 4, , 5]);
786
+ if (!booking.cartId) return [3 /*break*/, 3];
787
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
788
+ case 2:
787
789
  _a.sent();
788
- _a.label = 2;
789
- case 2: return [2 /*return*/, booking];
790
- case 3:
790
+ _a.label = 3;
791
+ case 3: return [2 /*return*/, booking];
792
+ case 4:
791
793
  error_1 = _a.sent();
794
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
795
+ // This error can occur when the user refreshes the page and the cart has expired
796
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
797
+ localStorage.removeItem("cartId");
798
+ booking.cartId = undefined;
799
+ return [2 /*return*/, booking];
800
+ }
792
801
  throw new Error("Could not instantiate JourneyBooking");
793
- case 4: return [2 /*return*/];
802
+ case 5: return [2 /*return*/];
794
803
  }
795
804
  });
796
805
  }); };
@@ -152,7 +152,7 @@ var ServiceBooking = /** @class */ (function (_super) {
152
152
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
153
153
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
154
154
  localStorage.removeItem("cartId");
155
- throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
155
+ throw new Error(response);
156
156
  }
157
157
  return response.cart;
158
158
  })];
@@ -649,18 +649,27 @@ exports.ServiceBooking = ServiceBooking;
649
649
  return __generator(this, function (_a) {
650
650
  switch (_a.label) {
651
651
  case 0:
652
- _a.trys.push([0, 3, , 4]);
653
652
  booking = new ServiceBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
654
- if (!booking.cartId) return [3 /*break*/, 2];
655
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
653
+ _a.label = 1;
656
654
  case 1:
655
+ _a.trys.push([1, 4, , 5]);
656
+ if (!booking.cartId) return [3 /*break*/, 3];
657
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
658
+ case 2:
657
659
  _a.sent();
658
- _a.label = 2;
659
- case 2: return [2 /*return*/, booking];
660
- case 3:
660
+ _a.label = 3;
661
+ case 3: return [2 /*return*/, booking];
662
+ case 4:
661
663
  error_1 = _a.sent();
662
- throw new Error("Could not instantiate ServiceBooking");
663
- case 4: return [2 /*return*/];
664
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
665
+ // This error can occur when the user refreshes the page and the cart has expired
666
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
667
+ localStorage.removeItem("cartId");
668
+ booking.cartId = undefined;
669
+ return [2 /*return*/, booking];
670
+ }
671
+ throw new Error("Could not instantiate JourneyBooking");
672
+ case 5: return [2 /*return*/];
664
673
  }
665
674
  });
666
675
  }); };
@@ -159,7 +159,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
159
159
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
160
160
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
161
161
  localStorage.removeItem("cartId");
162
- throw new Error("Error ".concat(response.httpStatus, " ").concat(response.message));
162
+ throw new Error(response);
163
163
  }
164
164
  return response.cart;
165
165
  })];
@@ -733,18 +733,27 @@ exports.SubscriptionBooking = SubscriptionBooking;
733
733
  return __generator(this, function (_a) {
734
734
  switch (_a.label) {
735
735
  case 0:
736
- _a.trys.push([0, 3, , 4]);
737
736
  booking = new SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
738
- if (!booking.cartId) return [3 /*break*/, 2];
739
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
737
+ _a.label = 1;
740
738
  case 1:
739
+ _a.trys.push([1, 4, , 5]);
740
+ if (!booking.cartId) return [3 /*break*/, 3];
741
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
742
+ case 2:
741
743
  _a.sent();
742
- _a.label = 2;
743
- case 2: return [2 /*return*/, booking];
744
- case 3:
744
+ _a.label = 3;
745
+ case 3: return [2 /*return*/, booking];
746
+ case 4:
745
747
  error_1 = _a.sent();
746
- throw new Error("Could not instantiate SubscriptionBooking");
747
- case 4: return [2 /*return*/];
748
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
749
+ // This error can occur when the user refreshes the page and the cart has expired
750
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
751
+ localStorage.removeItem("cartId");
752
+ booking.cartId = undefined;
753
+ return [2 /*return*/, booking];
754
+ }
755
+ throw new Error("Could not instantiate JourneyBooking");
756
+ case 5: return [2 /*return*/];
748
757
  }
749
758
  });
750
759
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "build": "tsc",
9
9
  "test": "jest --config jestconfig.json",
10
10
  "prepare": "npm run build",
11
- "prepublishOnly": "npm run test",
11
+ "prepublishOnly": "npm run test --runInBand",
12
12
  "version": "git add -A src",
13
13
  "postversion": "git push && git push --tags"
14
14
  },