mts-booking-library 1.1.9 → 1.1.10
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/lib/index.d.ts +1 -0
- package/lib/types/ErrorResponse.d.ts +4 -2
- package/lib/utils/apiCall.js +40 -18
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
@@ -4,6 +4,7 @@ export { ServiceBooking } from "./booking/serviceBooking";
|
|
4
4
|
export { SubscriptionBooking } from "./booking/subscriptionBooking";
|
5
5
|
export { Person, PassengersDetails, DEFAULT_PERSON } from "./types/common/Person";
|
6
6
|
export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType } from "./types/common/Tariffs";
|
7
|
+
export { ErrorResponse } from "./types/ErrorResponse";
|
7
8
|
export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
|
8
9
|
export { JourneyInfo } from "./types/journeys/JourneyInfo";
|
9
10
|
export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
|
@@ -1,10 +1,12 @@
|
|
1
1
|
/**
|
2
2
|
* @description Error response type as returned by the BackEnd
|
3
3
|
*
|
4
|
-
* @property {number}
|
4
|
+
* @property {number} httpStatus - The http status code of the error (e.g. 400)
|
5
|
+
* @property {number} mtsCode - The error code returned by the MTS Backend (e.g. 4001)
|
5
6
|
* @property {string} message - The message of the error (e.g. "Invalid parameters")
|
6
7
|
*/
|
7
8
|
export type ErrorResponse = {
|
8
|
-
|
9
|
+
httpStatus: number;
|
10
|
+
mtsCode: number;
|
9
11
|
message: string;
|
10
12
|
};
|
package/lib/utils/apiCall.js
CHANGED
@@ -59,27 +59,38 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
59
59
|
}
|
60
60
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
61
61
|
var response, error_1, resError;
|
62
|
-
|
63
|
-
|
62
|
+
var _a, _b, _c;
|
63
|
+
return __generator(this, function (_d) {
|
64
|
+
switch (_d.label) {
|
64
65
|
case 0:
|
65
|
-
|
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 =
|
71
|
+
response = _d.sent();
|
71
72
|
if (debug) {
|
72
73
|
console.log("GetResponseData", url, response.data);
|
73
74
|
}
|
74
75
|
resolve(response.data);
|
75
76
|
return [3 /*break*/, 3];
|
76
77
|
case 2:
|
77
|
-
error_1 =
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
error_1 = _d.sent();
|
79
|
+
if (axios_1.default.isAxiosError(error_1)) {
|
80
|
+
resError = {
|
81
|
+
httpStatus: ((_a = error_1.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
|
82
|
+
mtsCode: ((_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 500,
|
83
|
+
message: ((_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
|
84
|
+
};
|
85
|
+
if (debug) {
|
86
|
+
console.log("GetResponseError", url, resError);
|
87
|
+
}
|
88
|
+
reject(resError);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
// Not a axios error, return the error as is
|
92
|
+
reject(error_1);
|
81
93
|
}
|
82
|
-
reject(resError);
|
83
94
|
return [3 /*break*/, 3];
|
84
95
|
case 3: return [2 /*return*/];
|
85
96
|
}
|
@@ -97,27 +108,38 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
97
108
|
}
|
98
109
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
99
110
|
var response, error_2, resError;
|
100
|
-
|
101
|
-
|
111
|
+
var _a, _b, _c;
|
112
|
+
return __generator(this, function (_d) {
|
113
|
+
switch (_d.label) {
|
102
114
|
case 0:
|
103
|
-
|
115
|
+
_d.trys.push([0, 2, , 3]);
|
104
116
|
return [4 /*yield*/, axios_1.default.post(url, data, {
|
105
117
|
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
118
|
})];
|
107
119
|
case 1:
|
108
|
-
response =
|
120
|
+
response = _d.sent();
|
109
121
|
if (debug) {
|
110
122
|
console.log("PostResponseData", url, response.data);
|
111
123
|
}
|
112
124
|
resolve(response.data);
|
113
125
|
return [3 /*break*/, 3];
|
114
126
|
case 2:
|
115
|
-
error_2 =
|
116
|
-
|
117
|
-
|
118
|
-
|
127
|
+
error_2 = _d.sent();
|
128
|
+
if (axios_1.default.isAxiosError(error_2)) {
|
129
|
+
resError = {
|
130
|
+
httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
|
131
|
+
mtsCode: ((_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 500,
|
132
|
+
message: ((_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
|
133
|
+
};
|
134
|
+
if (debug) {
|
135
|
+
console.log("GetResponseError", url, resError);
|
136
|
+
}
|
137
|
+
reject(resError);
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
// Not a axios error, return the error as is
|
141
|
+
reject(error_2);
|
119
142
|
}
|
120
|
-
reject(resError);
|
121
143
|
return [3 /*break*/, 3];
|
122
144
|
case 3: return [2 /*return*/];
|
123
145
|
}
|