@yousolution/node-red-contrib-you-sap-service-layer 0.2.6 → 0.2.8

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/CHANGELOG.md CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- # [0.2.6] - 2025-01-16
5
+ # [0.2.8] - 2025-01-22
6
+
7
+ - Added error handling configuration from library or manual on ServiceSAP Node
8
+
9
+ # [0.2.7] - 2025-01-22
10
+
11
+ - Change Manage Error ServiceLayer on ServiceSAP Node
12
+
13
+ # [0.2.6] - 2025-01-18
6
14
 
7
15
  - Change Manage Empty Respose on ServiceSAP node
8
16
 
@@ -1,6 +1,7 @@
1
1
 
2
2
  function VerifyErrorSL (node, msg, response, consentEmpty=false) {
3
3
  if (!response.hasOwnProperty("success") && !response.hasOwnProperty("error") && !Object.keys(response).length && !consentEmpty) { // Error Generic
4
+
4
5
  msg.payload = response;
5
6
  node.error('Not Valid Requests', msg)
6
7
  node.status({ fill: 'red', shape: 'dot', text: 'Not Valid Requests' });
@@ -25,8 +26,9 @@ function VerifyErrorSL (node, msg, response, consentEmpty=false) {
25
26
  }
26
27
 
27
28
  }
28
- else { // OK Response
29
+ else { // OK Response
29
30
  return response;
31
+
30
32
  }
31
33
 
32
34
 
@@ -15,7 +15,8 @@
15
15
  serviceName: {value: ''},
16
16
  service: {value: ''},
17
17
  headers: {value: ''},
18
- bodyPost: {value: ''}
18
+ bodyPost: {value: ''},
19
+ manageError: {value: true}
19
20
  },
20
21
  inputs:1,
21
22
  outputs:1,
@@ -105,6 +106,10 @@
105
106
  <input type="text" id="node-input-bodyPost">
106
107
  <input type="hidden" id="node-input-bodyPost-type">
107
108
  </div>
109
+ <div class="form-row">
110
+ <label for="node-input-type"><i class="fa fa-cog"></i> Manage Error</label>
111
+ <input type="checkbox" id="node-input-manageError">
112
+ </div>
108
113
  </script>
109
114
 
110
115
  <!-- Documentation -->
@@ -129,6 +134,10 @@
129
134
  <span class="property-type">object</span>
130
135
  </dt>
131
136
  <dd> data to update to the entity </dd>
137
+ <dt>MangerError
138
+ <span class="property-type">Bool</span>
139
+ </dt>
140
+ <dd> Set Manage Error Respone on Library</dd>
132
141
  </dl>
133
142
 
134
143
  <h3>Outputs</h3>
@@ -18,16 +18,34 @@ module.exports = function (RED) {
18
18
  const data = msg[config.bodyPost];
19
19
  const options = { method: 'POST', hasRawQuery: false, isService: true, data: data };
20
20
  const login = Support.login;
21
- const result = await Support.sendRequest({ node, msg, config, axios, login, options });
22
- msg.payload = VerifyErrorSL(node, msg, result.data, true);//result.data;
23
- msg.statusCode = result.status;
24
- if(msg.payload) {
25
- node.status({ fill: 'green', shape: 'dot', text: 'success' });
21
+
22
+ const result = await Support.sendRequest({ node, msg, config, axios, login, options }, config.manageError);
23
+ if(config.manageError) {
24
+ msg.payload = VerifyErrorSL(node, msg, result.data, true);//result.data;
25
+ msg.statusCode = result.status;
26
+ if(result.status < 299) {
27
+ node.status({ fill: 'green', shape: 'dot', text: 'success' });
28
+ node.send(msg);
29
+ }
30
+ }
31
+ else {
32
+ msg.payload = result;
33
+ node.status({ fill: 'gray', shape: 'dot', text: 'Response Request' });
26
34
  node.send(msg);
27
35
  }
36
+
28
37
  } catch (error) {
29
- node.status({ fill: 'red', shape: 'dot', text: 'Error' });
30
- done(error);
38
+ if(!config.manageError) {
39
+ msg.payload = result;
40
+ node.status({ fill: 'gray', shape: 'dot', text: 'Response Request' });
41
+ node.send(msg);
42
+ }
43
+ else {
44
+ node.status({ fill: 'red', shape: 'dot', text: 'Error' });
45
+ done(error);
46
+ }
47
+
48
+
31
49
  }
32
50
  });
33
51
  }
package/nodes/support.js CHANGED
@@ -87,7 +87,7 @@ async function login(node, idAuth) {
87
87
  return await axiosLibrary(options);
88
88
  }
89
89
 
90
- async function sendRequest({ node, msg, config, axios, login, options }) {
90
+ async function sendRequest({ node, msg, config, axios, login, options }, manageError=true) {
91
91
  if (!node || !msg || !config || !axios || !login) {
92
92
  const missingParams = [];
93
93
  node ? null : missingParams.push('node');
@@ -102,7 +102,13 @@ async function sendRequest({ node, msg, config, axios, login, options }) {
102
102
  return await axios(requestOptions.axiosOptions);
103
103
  } catch (error) {
104
104
  // Refresh headers re-login
105
- if (error.response && (error.response.status == 401 || error.response.status == 301)) {
105
+ if(!manageError){
106
+ msg.statusCode = error.response.status;
107
+ msg.requestUrl = requestOptions.axiosOptions.url;
108
+ msg.payload = error.response.data;
109
+ return error.response.data;
110
+ }
111
+ else if (error.response && (error.response.status == 401 || error.response.status == 301)) {
106
112
  const globalCotext = node.context().global;
107
113
  // try {
108
114
  // update cookies for session timeout
@@ -130,12 +136,16 @@ async function sendRequest({ node, msg, config, axios, login, options }) {
130
136
  }
131
137
  // }
132
138
  }
133
- if (error.response && error.response.data) {
139
+ else if (error.response && error.response.data) {
134
140
  msg.statusCode = error.response.status;
135
141
  msg.payload = error.response.data;
136
142
  msg.requestUrl = requestOptions.axiosOptions.url;
137
- //node.send(msg);
138
- node.error(JSON.stringify(error.response.data), msg)
143
+ if(!manageError){
144
+ node.send(msg);
145
+ }
146
+ else {
147
+ node.error(JSON.stringify(error.response.data), msg)
148
+ }
139
149
  // throw new Error(JSON.stringify(error.response.data));
140
150
  }
141
151
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yousolution/node-red-contrib-you-sap-service-layer",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Unofficial module SAP Service Layer for NODE-RED",
5
5
  "license": "MIT",
6
6
  "scripts": {