Skip to content

Commit 68f0625

Browse files
committed
Do not nullify payload during errors
1 parent adeea8e commit 68f0625

6 files changed

+39
-28
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* JSONata for converting from NGSI Normalised format to Simplified representation with key-value pairs.
3+
*
4+
* @author Alexandre Alapetite <https://alexandra.dk/alexandre.alapetite>
5+
* @copyright Alexandra Institute <https://alexandra.dk> for the SynchroniCity European project <https://synchronicity-iot.eu> as a contribution to FIWARE <https://www.fiware.org>.
6+
* @license MIT
7+
* @date 2019-12-17 / 2019-12-17
8+
*/
9+
{
10+
"id": NoiseLevelObserved.id,
11+
"type": NoiseLevelObserved.type,
12+
"LAeq": NoiseLevelObserved.LAeq,
13+
"dateObservedFrom": NoiseLevelObserved.dateObserved,
14+
"dateObservedTo": NoiseLevelObserved.dateObserved,
15+
"location": NoiseLevelObserved.location
16+
}

json-multi-schema-resolver.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ module.exports = RED => {
5454
if (schemaUrl != '') {
5555
msg.schemaUrl = schemaUrl;
5656
} else {
57-
msg.payload = null;
5857
msg.error = util.format('Failed resolving schema using "%s"', mappingsUrl);
5958
}
6059
if (lastStatusError) {
@@ -64,7 +63,6 @@ module.exports = RED => {
6463
} catch (ex) {
6564
lastStatusError = true;
6665
node.status({ fill:'red', shape:'ring', text:'Error', });
67-
msg.payload = null;
6866
msg.error = util.format('Error resolving schema using "%s": %s', mappingsUrl, ex);
6967
}
7068
node.send(msg);

json-multi-schema-transformer.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,19 @@ module.exports = RED => {
9898
if (result) {
9999
msg.payload = result;
100100
} else {
101-
msg.payload = null;
101+
lastStatusError = true;
102+
node.status({ fill:'red', shape:'ring', text:'Error', });
102103
msg.error = util.format('Failed tranforming using "%s"', transformsUrl);
103104
}
104105
if (lastStatusError) {
105106
node.status({ fill:'green', shape:'dot', text:'OK', });
106107
lastStatusError = false;
107108
}
108-
} else {
109-
lastStatusError = true;
110-
node.status({ fill:'red', shape:'ring', text:'Error', });
111-
msg.payload = null;
112-
msg.error = util.format('Failed resolving tranforms using "%s"', transformsUrl);
113109
}
114110
} catch (ex) {
115111
lastStatusError = true;
116112
node.status({ fill:'red', shape:'ring', text:'Error', });
117-
msg.payload = null;
118-
msg.error = util.format('Error tranforming using "%s": %s', transformsUrl, ex);
113+
msg.error = util.format('Error tranforming using "%s": %s : %s', transformsUrl, ex, JSON.stringify(msg.payload));
119114
}
120115
node.send(msg);
121116
});

json-multi-schema-validator.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,25 @@ module.exports = RED => {
8686

8787
node.on('input', async msg => {
8888
delete msg.error;
89-
try {
90-
const result = await validateAsync(msg.schemaUrl, msg.payload);
91-
if (result === true) {
92-
msg.error = false;
93-
} else {
94-
msg.payload = null;
95-
msg.error = util.format('Failed validatation against "%s": %s', msg.schemaUrl, result);
96-
}
97-
if (lastStatusError) {
98-
node.status({ fill:'green', shape:'dot', text:'OK', });
99-
lastStatusError = false;
89+
if (msg.schemaUrl == '') {
90+
msg.error = 'Unknown schema!';
91+
} else {
92+
try {
93+
const result = await validateAsync(msg.schemaUrl, msg.payload);
94+
if (result === true) {
95+
msg.error = false;
96+
} else {
97+
msg.error = util.format('Failed validatation against "%s": %s', msg.schemaUrl, result);
98+
}
99+
if (lastStatusError) {
100+
node.status({ fill:'green', shape:'dot', text:'OK', });
101+
lastStatusError = false;
102+
}
103+
} catch (ex) {
104+
lastStatusError = true;
105+
node.status({ fill:'red', shape:'ring', text:'Error', });
106+
msg.error = util.format('Failed validatation against "%s": %s', msg.schemaUrl, ex);
100107
}
101-
} catch (ex) {
102-
lastStatusError = true;
103-
node.status({ fill:'red', shape:'ring', text:'Error', });
104-
msg.payload = null;
105-
msg.error = util.format('Failed validatation against "%s": %s', msg.schemaUrl, ex);
106108
}
107109
node.send(msg);
108110
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-json-multi-schema",
3-
"version": "0.3.5",
3+
"version": "0.4.0",
44
"description": "Generic JSON data pipeline tools, with dynamic transformation (using JSONata rules), resolving JSON Schema (using JSONata rules), and then validation (using JSON Schema). For Node-RED and for command-line.",
55
"main": "index.js",
66
"readmeFilename": "readme.md",

0 commit comments

Comments
 (0)