mts-booking-library 2.1.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/utils/apiCall.js +76 -48
- package/package.json +1 -1
package/lib/utils/apiCall.js
CHANGED
@@ -82,17 +82,17 @@ var makeGet = function (url, options) { return __awaiter(void 0, void 0, void 0,
|
|
82
82
|
}
|
83
83
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
84
84
|
var response, filteredResponse, error_1, message, resError, resError;
|
85
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
86
|
-
return __generator(this, function (
|
87
|
-
switch (
|
85
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
86
|
+
return __generator(this, function (_j) {
|
87
|
+
switch (_j.label) {
|
88
88
|
case 0:
|
89
|
-
|
89
|
+
_j.trys.push([0, 2, , 3]);
|
90
90
|
return [4 /*yield*/, axios_1.default.get(url, {
|
91
91
|
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
92
92
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
93
93
|
})];
|
94
94
|
case 1:
|
95
|
-
response =
|
95
|
+
response = _j.sent();
|
96
96
|
filteredResponse = removeNullError(response.data);
|
97
97
|
if (debug) {
|
98
98
|
console.log("GET_ResponseData", url, filteredResponse);
|
@@ -100,14 +100,21 @@ var makeGet = function (url, options) { return __awaiter(void 0, void 0, void 0,
|
|
100
100
|
resolve(filteredResponse);
|
101
101
|
return [3 /*break*/, 3];
|
102
102
|
case 2:
|
103
|
-
error_1 =
|
104
|
-
if (axios_1.default.
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
error_1 = _j.sent();
|
104
|
+
if (axios_1.default.isCancel(error_1)) {
|
105
|
+
// Log cancellation
|
106
|
+
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
107
|
+
console.log("GET_ResponseCancelled", url);
|
108
|
+
// Resolve with empty object
|
109
|
+
resolve({});
|
110
|
+
}
|
111
|
+
else if (axios_1.default.isAxiosError(error_1)) {
|
112
|
+
message = ((_b = (_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
113
|
+
? error_1.response.data.error.message
|
114
|
+
: (_d = (_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
108
115
|
resError = {
|
109
|
-
httpStatus: ((
|
110
|
-
mtsCode: ((
|
116
|
+
httpStatus: ((_e = error_1.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
117
|
+
mtsCode: ((_h = (_g = (_f = error_1.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
|
111
118
|
message: message || "Unknown error"
|
112
119
|
};
|
113
120
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
@@ -144,17 +151,17 @@ var makePost = function (url, data, options) { return __awaiter(void 0, void 0,
|
|
144
151
|
}
|
145
152
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
146
153
|
var response, filteredResponse, error_2, message, resError, resError;
|
147
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
148
|
-
return __generator(this, function (
|
149
|
-
switch (
|
154
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
155
|
+
return __generator(this, function (_j) {
|
156
|
+
switch (_j.label) {
|
150
157
|
case 0:
|
151
|
-
|
158
|
+
_j.trys.push([0, 2, , 3]);
|
152
159
|
return [4 /*yield*/, axios_1.default.post(url, data, {
|
153
160
|
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
154
161
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
155
162
|
})];
|
156
163
|
case 1:
|
157
|
-
response =
|
164
|
+
response = _j.sent();
|
158
165
|
filteredResponse = removeNullError(response.data);
|
159
166
|
if (debug) {
|
160
167
|
console.log("POST_ResponseData", url, filteredResponse);
|
@@ -162,14 +169,21 @@ var makePost = function (url, data, options) { return __awaiter(void 0, void 0,
|
|
162
169
|
resolve(filteredResponse);
|
163
170
|
return [3 /*break*/, 3];
|
164
171
|
case 2:
|
165
|
-
error_2 =
|
166
|
-
if (axios_1.default.
|
167
|
-
|
168
|
-
|
169
|
-
|
172
|
+
error_2 = _j.sent();
|
173
|
+
if (axios_1.default.isCancel(error_2)) {
|
174
|
+
// Log cancellation
|
175
|
+
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
176
|
+
console.log("POST_ResponseCancelled", url);
|
177
|
+
// Resolve with empty object
|
178
|
+
resolve({});
|
179
|
+
}
|
180
|
+
else if (axios_1.default.isAxiosError(error_2)) {
|
181
|
+
message = ((_b = (_a = error_2.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
182
|
+
? error_2.response.data.error.message
|
183
|
+
: (_d = (_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
170
184
|
resError = {
|
171
|
-
httpStatus: ((
|
172
|
-
mtsCode: ((
|
185
|
+
httpStatus: ((_e = error_2.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
186
|
+
mtsCode: ((_h = (_g = (_f = error_2.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
|
173
187
|
message: message || "Unknown error"
|
174
188
|
};
|
175
189
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
@@ -206,17 +220,17 @@ var makePut = function (url, data, options) { return __awaiter(void 0, void 0, v
|
|
206
220
|
}
|
207
221
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
208
222
|
var response, filteredResponse, error_3, message, resError, resError;
|
209
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
210
|
-
return __generator(this, function (
|
211
|
-
switch (
|
223
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
224
|
+
return __generator(this, function (_j) {
|
225
|
+
switch (_j.label) {
|
212
226
|
case 0:
|
213
|
-
|
227
|
+
_j.trys.push([0, 2, , 3]);
|
214
228
|
return [4 /*yield*/, axios_1.default.put(url, data, {
|
215
229
|
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
216
230
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
217
231
|
})];
|
218
232
|
case 1:
|
219
|
-
response =
|
233
|
+
response = _j.sent();
|
220
234
|
filteredResponse = removeNullError(response.data);
|
221
235
|
if (debug) {
|
222
236
|
console.log("PUT_ResponseData", url, filteredResponse);
|
@@ -224,14 +238,21 @@ var makePut = function (url, data, options) { return __awaiter(void 0, void 0, v
|
|
224
238
|
resolve(filteredResponse);
|
225
239
|
return [3 /*break*/, 3];
|
226
240
|
case 2:
|
227
|
-
error_3 =
|
228
|
-
if (axios_1.default.
|
229
|
-
|
230
|
-
|
231
|
-
|
241
|
+
error_3 = _j.sent();
|
242
|
+
if (axios_1.default.isCancel(error_3)) {
|
243
|
+
// Log cancellation
|
244
|
+
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
245
|
+
console.log("PUT_ResponseCancelled", url);
|
246
|
+
// Resolve with empty object
|
247
|
+
resolve({});
|
248
|
+
}
|
249
|
+
else if (axios_1.default.isAxiosError(error_3)) {
|
250
|
+
message = ((_b = (_a = error_3.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
251
|
+
? error_3.response.data.error.message
|
252
|
+
: (_d = (_c = error_3.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
232
253
|
resError = {
|
233
|
-
httpStatus: ((
|
234
|
-
mtsCode: ((
|
254
|
+
httpStatus: ((_e = error_3.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
255
|
+
mtsCode: ((_h = (_g = (_f = error_3.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
|
235
256
|
message: message || "Unknown error"
|
236
257
|
};
|
237
258
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
@@ -268,17 +289,17 @@ var makeDelete = function (url, options) { return __awaiter(void 0, void 0, void
|
|
268
289
|
}
|
269
290
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
270
291
|
var response, filteredResponse, error_4, message, resError, resError;
|
271
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
272
|
-
return __generator(this, function (
|
273
|
-
switch (
|
292
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
293
|
+
return __generator(this, function (_j) {
|
294
|
+
switch (_j.label) {
|
274
295
|
case 0:
|
275
|
-
|
296
|
+
_j.trys.push([0, 2, , 3]);
|
276
297
|
return [4 /*yield*/, axios_1.default.delete(url, {
|
277
298
|
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID })),
|
278
299
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
279
300
|
})];
|
280
301
|
case 1:
|
281
|
-
response =
|
302
|
+
response = _j.sent();
|
282
303
|
filteredResponse = removeNullError(response.data);
|
283
304
|
if (debug) {
|
284
305
|
console.log("DELETE_ResponseData", url, filteredResponse);
|
@@ -286,14 +307,21 @@ var makeDelete = function (url, options) { return __awaiter(void 0, void 0, void
|
|
286
307
|
resolve(filteredResponse);
|
287
308
|
return [3 /*break*/, 3];
|
288
309
|
case 2:
|
289
|
-
error_4 =
|
290
|
-
if (axios_1.default.
|
291
|
-
|
292
|
-
|
293
|
-
|
310
|
+
error_4 = _j.sent();
|
311
|
+
if (axios_1.default.isCancel(error_4)) {
|
312
|
+
// Log cancellation
|
313
|
+
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST)
|
314
|
+
console.log("DELETE_ResponseCancelled", url);
|
315
|
+
// Resolve with empty object
|
316
|
+
resolve({});
|
317
|
+
}
|
318
|
+
else if (axios_1.default.isAxiosError(error_4)) {
|
319
|
+
message = ((_b = (_a = error_4.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)
|
320
|
+
? error_4.response.data.error.message
|
321
|
+
: (_d = (_c = error_4.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message;
|
294
322
|
resError = {
|
295
|
-
httpStatus: ((
|
296
|
-
mtsCode: ((
|
323
|
+
httpStatus: ((_e = error_4.response) === null || _e === void 0 ? void 0 : _e.status) || 0,
|
324
|
+
mtsCode: ((_h = (_g = (_f = error_4.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.code) || 0,
|
297
325
|
message: message || "Unknown error"
|
298
326
|
};
|
299
327
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|