mts-booking-library 1.1.9 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,28 +58,45 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
58
58
  console.log("GetRequestData", url);
59
59
  }
60
60
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
61
- var response, error_1, resError;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
61
+ var response_1, filteredResponse_1, error_1, resError, resError;
62
+ var _a, _b, _c;
63
+ return __generator(this, function (_d) {
64
+ switch (_d.label) {
64
65
  case 0:
65
- _a.trys.push([0, 2, , 3]);
66
+ _d.trys.push([0, 2, , 3]);
66
67
  return [4 /*yield*/, axios_1.default.get(url, {
67
68
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
68
69
  })];
69
70
  case 1:
70
- response = _a.sent();
71
+ response_1 = _d.sent();
72
+ filteredResponse_1 = {};
73
+ Object.keys(response_1.data).filter(function (key) { return key !== "error"; })
74
+ .map(function (key) {
75
+ var _a;
76
+ return filteredResponse_1 = __assign(__assign({}, filteredResponse_1), (_a = {}, _a[key] = response_1.data[key], _a));
77
+ });
71
78
  if (debug) {
72
- console.log("GetResponseData", url, response.data);
79
+ console.log("GetResponseData", url, filteredResponse_1);
73
80
  }
74
- resolve(response.data);
81
+ resolve(filteredResponse_1);
75
82
  return [3 /*break*/, 3];
76
83
  case 2:
77
- error_1 = _a.sent();
78
- resError = error_1.response.data;
79
- if (debug) {
80
- console.log("GetResponseError", url, resError);
84
+ error_1 = _d.sent();
85
+ if (axios_1.default.isAxiosError(error_1)) {
86
+ resError = {
87
+ httpStatus: ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.status) || 0,
88
+ mtsCode: ((_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 0,
89
+ message: ((_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
90
+ };
91
+ if (debug) {
92
+ console.log("GetResponseError", url, resError);
93
+ }
94
+ reject(resError);
95
+ }
96
+ else {
97
+ resError = __assign(__assign({}, error_1), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
98
+ reject(resError);
81
99
  }
82
- reject(resError);
83
100
  return [3 /*break*/, 3];
84
101
  case 3: return [2 /*return*/];
85
102
  }
@@ -97,27 +114,38 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
97
114
  }
98
115
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
99
116
  var response, error_2, resError;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
117
+ var _a, _b, _c;
118
+ return __generator(this, function (_d) {
119
+ switch (_d.label) {
102
120
  case 0:
103
- _a.trys.push([0, 2, , 3]);
121
+ _d.trys.push([0, 2, , 3]);
104
122
  return [4 /*yield*/, axios_1.default.post(url, data, {
105
123
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
106
124
  })];
107
125
  case 1:
108
- response = _a.sent();
126
+ response = _d.sent();
109
127
  if (debug) {
110
128
  console.log("PostResponseData", url, response.data);
111
129
  }
112
130
  resolve(response.data);
113
131
  return [3 /*break*/, 3];
114
132
  case 2:
115
- error_2 = _a.sent();
116
- resError = error_2.response.data;
117
- if (debug) {
118
- console.log("PostResponseError", url, resError);
133
+ error_2 = _d.sent();
134
+ if (axios_1.default.isAxiosError(error_2)) {
135
+ resError = {
136
+ httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
137
+ mtsCode: ((_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 500,
138
+ message: ((_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
139
+ };
140
+ if (debug) {
141
+ console.log("GetResponseError", url, resError);
142
+ }
143
+ reject(resError);
144
+ }
145
+ else {
146
+ // Not a axios error, return the error as is
147
+ reject(error_2);
119
148
  }
120
- reject(resError);
121
149
  return [3 /*break*/, 3];
122
150
  case 3: return [2 /*return*/];
123
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.1.9",
3
+ "version": "1.2.0",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
- "@types/jest": "^29.5.5",
17
+ "@types/jest": "^29.5.7",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.1",
20
20
  "typescript": "^5.2.2"
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "author": "M",
30
30
  "dependencies": {
31
- "axios": "^1.5.1",
31
+ "axios": "^1.6.0",
32
32
  "node-localstorage": "^3.0.5"
33
33
  }
34
34
  }