mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	debug node: add auto handling of error and status msgs if set to show status
This commit is contained in:
		| @@ -52,7 +52,7 @@ | ||||
|             complete: {value:"false", required:true}, | ||||
|             targetType: {value:undefined}, | ||||
|             statusVal: {value:""}, | ||||
|             statusType: {value:"msg"} | ||||
|             statusType: {value:"auto"} | ||||
|         }, | ||||
|         label: function() { | ||||
|             var suffix = ""; | ||||
| @@ -318,9 +318,14 @@ | ||||
|             delete RED._debug; | ||||
|         }, | ||||
|         oneditprepare: function() { | ||||
|             var autoType = { | ||||
|                 value: "auto", | ||||
|                 label: RED._("node-red:debug.autostatus"), | ||||
|                 hasValue: false | ||||
|             }; | ||||
|             $("#node-input-typed-status").typedInput({ | ||||
|                 default: "msg", | ||||
|                 types:['msg',"jsonata"], | ||||
|                 default: "auto", | ||||
|                 types:[autoType, "msg", "jsonata"], | ||||
|                 typeField: $("#node-input-statusType") | ||||
|             }); | ||||
|             var that = this; | ||||
| @@ -339,7 +344,7 @@ | ||||
|             } | ||||
|             if (this.statusType === undefined) { | ||||
|                 this.statusType = this.targetType; | ||||
|                 $("#node-input-typed-status").typedInput('type',this.statusType || "msg"); | ||||
|                 $("#node-input-typed-status").typedInput('type',this.statusType || "auto"); | ||||
|             } | ||||
|             if (typeof this.console === "string") { | ||||
|                 this.console = (this.console == 'true'); | ||||
| @@ -385,7 +390,7 @@ | ||||
|                         if (type !== 'full') { | ||||
|                             comp = $("#node-input-typed-complete").typedInput('value'); | ||||
|                         } | ||||
|                         that.statusType = (type !== "jsonata") ? "msg" : "jsonata"; | ||||
|                         that.statusType = "auto"; | ||||
|                         that.statusVal = comp; | ||||
|                     } | ||||
|                     $("#node-input-typed-status").typedInput('type',that.statusType); | ||||
| @@ -394,7 +399,7 @@ | ||||
|                 } | ||||
|                 else { | ||||
|                     $("#node-tostatus-line").hide(); | ||||
|                     that.statusType = "msg"; | ||||
|                     that.statusType = "auto"; | ||||
|                     that.statusVal = ""; | ||||
|                     $("#node-input-typed-status").typedInput('type',that.statusType); | ||||
|                     $("#node-input-typed-status").typedInput('value',that.statusVal); | ||||
|   | ||||
| @@ -69,18 +69,32 @@ module.exports = function(RED) { | ||||
|         } | ||||
|  | ||||
|         function prepareStatus(msg, done) { | ||||
|             // Either apply the jsonata expression or... | ||||
|             if (preparedStatExpression) { | ||||
|                 RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => { | ||||
|                     if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); }  | ||||
|                     else { done(null,{msg:value}); } | ||||
|                 }); | ||||
|             } else { | ||||
|                 // Extract the required message property | ||||
|                 var output; | ||||
|                 try { output = RED.util.getMessageProperty(msg,node.statusVal); } | ||||
|                 catch(err) { output = undefined; } | ||||
|                 done(null,{msg:output}); | ||||
|             if (node.statusType === "auto") { | ||||
|                 if (node.complete === "true") { | ||||
|                     done(null,{msg:msg.payload}); | ||||
|                 } | ||||
|                 else { | ||||
|                     prepareValue(msg,function(err,debugMsg) { | ||||
|                         if (err) { node.error(err); return; } | ||||
|                         done(null,{msg:debugMsg.msg}); | ||||
|                     }); | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|                 // Either apply the jsonata expression or... | ||||
|                 if (preparedStatExpression) { | ||||
|                     RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => { | ||||
|                         if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); }  | ||||
|                         else { done(null,{msg:value}); } | ||||
|                     }); | ||||
|                 }  | ||||
|                 else { | ||||
|                     // Extract the required message property | ||||
|                     var output; | ||||
|                     try { output = RED.util.getMessageProperty(msg,node.statusVal); } | ||||
|                     catch(err) { output = undefined; } | ||||
|                     done(null,{msg:output}); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -93,10 +107,16 @@ module.exports = function(RED) { | ||||
|                     if (st.length > 32) { st = st.substr(0,32) + "..."; } | ||||
|                     var fill = "grey"; | ||||
|                     var shape = "dot"; | ||||
|                     if (node.statusVal === "error.message" && msg.hasOwnProperty("error")) { fill = "red"; } | ||||
|                     if (node.statusVal === "status.text" && msg.hasOwnProperty("status")) { | ||||
|                         if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; } | ||||
|                         if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; } | ||||
|                     if (node.statusType === "auto") { | ||||
|                         if (msg.hasOwnProperty("error")) {  | ||||
|                             fill = "red";  | ||||
|                             st = msg.error.message; | ||||
|                         } | ||||
|                         if (msg.hasOwnProperty("status")) { | ||||
|                             if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; } | ||||
|                             if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; } | ||||
|                             if (msg.status.hasOwnProperty("text")) { st = msg.status.text; } | ||||
|                         } | ||||
|                     } | ||||
|                     node.status({fill:fill, shape:shape, text:st}); | ||||
|                 }); | ||||
|   | ||||
| @@ -123,6 +123,7 @@ | ||||
|         "invalid-exp": "Invalid JSONata expression: __error__", | ||||
|         "msgprop": "message property", | ||||
|         "msgobj": "complete msg object", | ||||
|         "autostatus": "automatic", | ||||
|         "to": "To", | ||||
|         "debtab": "debug tab", | ||||
|         "tabcon": "debug tab and console", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user