uapi-json 1.17.0 → 1.17.2

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/docs/Terminal.md CHANGED
@@ -26,6 +26,8 @@ on how to use emulation.
26
26
  In case you want to handle some specific errors from uAPI, you can provde `uapiErrorHandler` function
27
27
  in options.
28
28
 
29
+ Function should return response from retried command or any other command.
30
+
29
31
  Footprint of the functions should be as follows:
30
32
  ```javascript
31
33
  async (
@@ -33,6 +35,8 @@ async (
33
35
  { command, error: err }
34
36
  ) => {
35
37
  // your code goes here
38
+ // response is an array of strings (lines of terminal response)
39
+ return response;
36
40
  }
37
41
  ```
38
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uapi-json",
3
- "version": "1.17.0",
3
+ "version": "1.17.2",
4
4
  "description": "Travelport Universal API",
5
5
  "main": "src/",
6
6
  "files": [
@@ -75,61 +75,71 @@ module.exports = function uapiRequest(
75
75
  return reqType;
76
76
  }));
77
77
 
78
- const sendRequest = function (xml) {
78
+ const sendRequest = async (xml) => {
79
79
  if (debugMode) {
80
80
  log('Request URL: ', service);
81
81
  log('Request XML: ', pd.xml(xml));
82
82
  }
83
- return axios.request({
84
- url: service,
85
- method: 'POST',
86
- timeout: config.timeout || 5000,
87
- auth: {
88
- username: auth.username,
89
- password: auth.password,
90
- },
91
- headers: {
92
- 'Accept-Encoding': 'gzip',
93
- 'Content-Type': 'text/xml',
94
- },
95
- data: xml,
96
- })
97
- .then((response) => {
98
- if (debugMode) {
99
- log('Response SOAP: ', pd.xml(response.data));
100
- }
101
- return response.data;
102
- })
103
- .catch((e) => {
104
- const rsp = e.response;
105
83
 
106
- if (['ECONNREFUSED', 'ECONNRESET'].includes(e.code)) {
107
- return Promise.reject(new RequestRuntimeError.UAPIServiceError(e));
108
- }
84
+ try {
85
+ const response = await axios.request({
86
+ url: service,
87
+ method: 'POST',
88
+ timeout: config.timeout || 5000,
89
+ auth: {
90
+ username: auth.username,
91
+ password: auth.password,
92
+ },
93
+ headers: {
94
+ 'Accept-Encoding': 'gzip',
95
+ 'Content-Type': 'text/xml',
96
+ },
97
+ data: xml,
98
+ });
109
99
 
110
- if (['ECONNABORTED'].includes(e.code)) {
111
- return Promise.reject(new RequestRuntimeError.UAPIServiceTimeout(e));
112
- }
100
+ if (debugMode) {
101
+ log('Response SOAP: ', pd.xml(response.data));
102
+ }
113
103
 
114
- if (!rsp) {
115
- if (debugMode) {
116
- log('Unexpected Error: ', pd.json(e));
117
- }
104
+ return response.data;
105
+ } catch (e) {
106
+ const rsp = e.response;
118
107
 
119
- return Promise.reject(new RequestSoapError.SoapUnexpectedError(e));
108
+ if (['ECONNREFUSED', 'ECONNRESET'].includes(e.code)) {
109
+ throw new RequestRuntimeError.UAPIServiceError(e);
110
+ }
111
+
112
+ if (['ECONNABORTED'].includes(e.code)) {
113
+ throw new RequestRuntimeError.UAPIServiceTimeout(e);
114
+ }
115
+
116
+ if (!rsp) {
117
+ if (debugMode) {
118
+ log('Unexpected Error: ', pd.json(e));
120
119
  }
121
120
 
122
- const error = {
123
- status: rsp.status,
124
- data: rsp.data,
125
- };
121
+ throw new RequestSoapError.SoapUnexpectedError(e);
122
+ }
126
123
 
124
+ // TVPT error response with 500 header
125
+ if (rsp.data.toUpperCase().includes('SOAP:FAULT')) {
127
126
  if (debugMode) {
128
- log('Error Response SOAP: ', pd.json(error));
127
+ log('Response SOAP: ', pd.xml(rsp.data));
129
128
  }
129
+ return rsp.data;
130
+ }
130
131
 
131
- return Promise.reject(new RequestSoapError.SoapRequestError(error));
132
- });
132
+ const error = {
133
+ status: rsp.status,
134
+ data: rsp.data,
135
+ };
136
+
137
+ if (debugMode) {
138
+ log('Error Response SOAP: ', pd.json(error));
139
+ }
140
+
141
+ throw new RequestSoapError.SoapRequestError(error);
142
+ }
133
143
  };
134
144
 
135
145
  const parseResponse = function (response, parseParams) {
@@ -146,6 +156,7 @@ module.exports = function uapiRequest(
146
156
  };
147
157
 
148
158
  const validateSOAP = function (parsedXML) {
159
+ console.log(parsedXML);
149
160
  if (parsedXML['SOAP:Fault']) {
150
161
  if (debugMode > 2) {
151
162
  log('Parsed error response', pd.json(parsedXML));
@@ -170,7 +170,7 @@ module.exports = function (settings) {
170
170
  } catch (e) {
171
171
  if (!isErrorRetriable(e) || times <= 0) {
172
172
  if (uapiErrorHandler) {
173
- await uapiErrorHandler(
173
+ return uapiErrorHandler(
174
174
  executeCommandWithRetry,
175
175
  { command, error: e }
176
176
  );