mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #4632 from node-red/4625-sf-env-err-handling
Add validation and error handling on subflow instance properties
This commit is contained in:
commit
19dcc3a683
@ -1029,7 +1029,22 @@ RED.nodes = (function() {
|
|||||||
RED.nodes.registerType("subflow:"+sf.id, {
|
RED.nodes.registerType("subflow:"+sf.id, {
|
||||||
defaults:{
|
defaults:{
|
||||||
name:{value:""},
|
name:{value:""},
|
||||||
env:{value:[]}
|
env:{value:[], validate: function(value) {
|
||||||
|
const errors = []
|
||||||
|
if (value) {
|
||||||
|
value.forEach(env => {
|
||||||
|
const r = RED.utils.validateTypedProperty(env.value, env.type)
|
||||||
|
if (r !== true) {
|
||||||
|
errors.push(env.name+': '+r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (errors.length === 0) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
}}
|
||||||
},
|
},
|
||||||
icon: function() { return sf.icon||"subflow.svg" },
|
icon: function() { return sf.icon||"subflow.svg" },
|
||||||
category: sf.category || "subflows",
|
category: sf.category || "subflows",
|
||||||
|
@ -106,15 +106,23 @@ async function evaluateEnvProperties(flow, env, credentials) {
|
|||||||
result = { value: result, __clone__: true}
|
result = { value: result, __clone__: true}
|
||||||
}
|
}
|
||||||
evaluatedEnv[name] = result
|
evaluatedEnv[name] = result
|
||||||
|
} else {
|
||||||
|
evaluatedEnv[name] = undefined
|
||||||
|
flow.error(`Error evaluating env property '${name}': ${err.toString()}`)
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
});
|
});
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
value = redUtil.evaluateNodeProperty(value, type, {_flow: flow}, null, null);
|
value = redUtil.evaluateNodeProperty(value, type, {_flow: flow}, null, null);
|
||||||
if (typeof value === 'object') {
|
if (typeof value === 'object') {
|
||||||
value = { value: value, __clone__: true}
|
value = { value: value, __clone__: true}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
value = undefined
|
||||||
|
flow.error(`Error evaluating env property '${name}': ${err.toString()}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
evaluatedEnv[name] = value
|
evaluatedEnv[name] = value
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user