Skip to content

Commit 21a5da1

Browse files
committed
Do not override payload during transformation error
1 parent 96417be commit 21a5da1

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

json-multi-schema-resolver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ module.exports = RED => {
4848

4949
node.on('input', async msg => {
5050
delete msg.schemaUrl;
51-
msg.error = msg.error ? msg.error + ' ; ' : '';
5251
try {
5352
const schemaUrl = await resolveAsync(msg.payload);
5453
if (schemaUrl != '') {
5554
msg.schemaUrl = schemaUrl;
56-
msg.error = msg.error != '';
55+
msg.error = msg.error ? msg.error : false;
5756
}
5857
if (lastStatusError) {
5958
node.status({ fill:'green', shape:'dot', text:'OK', });
@@ -62,6 +61,7 @@ module.exports = RED => {
6261
} catch (ex) {
6362
lastStatusError = true;
6463
node.status({ fill:'red', shape:'ring', text:'Error', });
64+
msg.error = msg.error ? msg.error + ' ; ' : '';
6565
msg.error += util.format('Error resolving schema using "%s": %s', mappingsUrl, ex);
6666
}
6767
node.send(msg);

json-multi-schema-transformer.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ module.exports = RED => {
2828
* Transform the given payload with the JSONata expression given in URL.
2929
*/
3030
async function transformAsync(payload, transformUrl) {
31-
if (!transformUrl) {
32-
return 'Error: Invalid JSONata URL';
33-
}
34-
3531
let jsonataExpression;
3632
let jsonataCache = jsonatas[transformUrl];
3733
if (jsonataCache) {
@@ -66,7 +62,7 @@ module.exports = RED => {
6662

6763
node.on('input', async msg => {
6864
msg.error = msg.error ? msg.error + ' ; ' : '';
69-
if (msg.schemaUrl != '') {
65+
if (msg.schemaUrl) {
7066
msg.transformUrl = msg.schemaUrl;
7167
try {
7268
const result = await transformAsync(msg.payload, msg.schemaUrl);
@@ -83,6 +79,7 @@ module.exports = RED => {
8379
} catch (ex) {
8480
lastStatusError = true;
8581
node.status({ fill:'red', shape:'ring', text:'Error', });
82+
console.error('Schema2 ' + msg.schemaUrl);
8683
msg.error += util.format('Error tranforming using "%s": %s', msg.schemaUrl, ex);
8784
}
8885
}

json-multi-schema-validator.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ module.exports = RED => {
3434
* Validate the given payload with the JSON Schema given in URL.
3535
*/
3636
async function validateAsync(payload, schemaUrl) {
37-
if (!schemaUrl) {
38-
return 'Error: Invalid JSON schema URL';
39-
}
40-
4137
let validatorCache = validators[schemaUrl];
4238
if (validatorCache) {
4339
if (validatorCache.validator === null) {
@@ -90,7 +86,7 @@ module.exports = RED => {
9086

9187
node.on('input', async msg => {
9288
msg.error = msg.error ? msg.error + ' ; ' : '';
93-
if (msg.schemaUrl != '') {
89+
if (msg.schemaUrl) {
9490
msg.validUrl = msg.schemaUrl;
9591
try {
9692
const result = await validateAsync(msg.payload, msg.schemaUrl);

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.5.1",
3+
"version": "0.5.2",
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)