Catches bad objects being encoded, returning instead the error.

Symptom- Observed that global context would not display in front end, the call returning 400.
Traced to an object in global which cause encodeObject to except.
This push catches that, and now global will display, but the object in question display as an error.
This commit is contained in:
Simon Hailes 2019-11-01 11:38:26 +00:00
parent 6f91786f4d
commit bc283aa025

View File

@ -652,6 +652,7 @@ function normaliseNodeTypeName(name) {
* @memberof @node-red/util_util
*/
function encodeObject(msg,opts) {
try {
var debuglength = 1000;
if (opts && opts.hasOwnProperty('maxLength')) {
debuglength = opts.maxLength;
@ -776,6 +777,20 @@ function encodeObject(msg,opts) {
}
}
return msg;
} catch(e) {
msg.format = "error";
var errorMsg = {};
if (e.name) {
errorMsg.name = e.name;
}
if (e.hasOwnProperty('message')) {
errorMsg.message = e.message;
} else {
errorMsg.message = e.toString();
}
msg.msg = JSON.stringify(errorMsg);
return msg;
}
}
module.exports = {