From 08b6df86c514b5ba1f76cca4c3d114098ecd3d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6llenbeck?= Date: Thu, 14 Nov 2024 20:54:00 +0100 Subject: [PATCH] Add error handling to nodes --- endevent-finished-listener.js | 11 ++++-- nodered/flows.json | 11 ++++++ package.json | 2 +- process-event-listener.js | 63 ++++++++++++++++++++++++++++------- processdefinition-query.js | 5 ++- usertask-event-listener.js | 10 +++++- 6 files changed, 85 insertions(+), 17 deletions(-) diff --git a/endevent-finished-listener.js b/endevent-finished-listener.js index 2ac66ef..86a4935 100644 --- a/endevent-finished-listener.js +++ b/endevent-finished-listener.js @@ -20,7 +20,9 @@ module.exports = function (RED) { }); }, { identity: currentIdentity }, - ); + ).catch((error) => { + node.error(error); + }); node.engine.registerOnIdentityChanged(async (identity) => { client.events.removeSubscription(subscription, currentIdentity); @@ -34,7 +36,12 @@ module.exports = function (RED) { }); }, { identity: currentIdentity }, - ); + ).catch((error) => { + node.error(error); + }); + + }).catch((error) => { + node.error(error); }); node.on('close', async () => { diff --git a/nodered/flows.json b/nodered/flows.json index 25301cd..65ea251 100644 --- a/nodered/flows.json +++ b/nodered/flows.json @@ -479,6 +479,17 @@ "name": "Engine Auth 8000", "url": "http://engine:8000" }, + { + "id": "392373f3e1403770", + "type": "processcube-engine-config", + "name": "", + "url": "http://host.docker.internal:56000", + "urlType": "str", + "clientId": "", + "clientIdType": "str", + "clientSecret": "", + "clientSecretType": "str" + }, { "id": "2991a5e6df2b87d2", "type": "externaltask-input", diff --git a/package.json b/package.json index da520bb..549f3d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@5minds/node-red-contrib-processcube", - "version": "1.5.4", + "version": "1.5.5", "license": "MIT", "description": "Node-RED nodes for ProcessCube", "scripts": { diff --git a/process-event-listener.js b/process-event-listener.js index de9e3b1..ee689e9 100644 --- a/process-event-listener.js +++ b/process-event-listener.js @@ -54,7 +54,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'started': return await client.notification.onProcessStarted( async (processNotification) => { @@ -70,6 +72,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -91,7 +95,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'resumed': return await client.notification.onProcessResumed( async (processNotification) => { @@ -108,6 +114,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -128,7 +136,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'finished': return await client.notification.onProcessEnded( async (processNotification) => { @@ -145,6 +155,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -166,7 +178,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'terminated': return await client.notification.onProcessTerminated( async (processNotification) => { @@ -183,6 +197,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -203,7 +219,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'error': return await client.notification.onProcessError( async (processNotification) => { @@ -220,6 +238,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -240,7 +260,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'owner-changed': return await client.notification.onProcessOwnerChanged( async (processNotification) => { @@ -257,6 +279,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -276,7 +300,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'instances-deleted': return await client.notification.onProcessInstancesDeleted( async (processNotification) => { @@ -293,6 +319,8 @@ module.exports = function (RED) { const matchingInstances = await client.processInstances.query(newQuery, { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); if ( @@ -312,7 +340,9 @@ module.exports = function (RED) { } }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'is-executable-changed': return await client.notification.onProcessIsExecutableChanged( (processNotification) => { @@ -330,7 +360,9 @@ module.exports = function (RED) { }); }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'deployed': return await client.notification.onProcessDeployed( (processNotification) => { @@ -348,7 +380,9 @@ module.exports = function (RED) { }); }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); case 'undeployed': return await client.notification.onProcessUndeployed( (processNotification) => { @@ -366,7 +400,9 @@ module.exports = function (RED) { }); }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); default: console.error('no such event: ' + eventType); break; @@ -399,7 +435,10 @@ module.exports = function (RED) { }); }, { identity: currentIdentity } - ); + ).catch((error) => { + node.error(error); + }); + }); node.on('close', () => { diff --git a/processdefinition-query.js b/processdefinition-query.js index 4398b89..8b51c21 100644 --- a/processdefinition-query.js +++ b/processdefinition-query.js @@ -17,9 +17,10 @@ module.exports = function (RED) { query = { ...query, - identity: engine.identity, + identity: undefined, }; + node.log(`Querying process definitions with query: ${JSON.stringify(query)}`); client.processDefinitions.getAll(query).then((matchingProcessDefinitions) => { if (config.models_only && matchingProcessDefinitions.totalCount > 0) { @@ -40,6 +41,8 @@ module.exports = function (RED) { } node.send(msg); + }).catch((error) => { + node.error(error); }); }); } diff --git a/usertask-event-listener.js b/usertask-event-listener.js index 3948a92..55b7b0b 100644 --- a/usertask-event-listener.js +++ b/usertask-event-listener.js @@ -50,18 +50,26 @@ module.exports = function (RED) { case 'new': return await client.userTasks.onUserTaskWaiting(userTaskCallback(), { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); case 'finished': return await client.userTasks.onUserTaskFinished(userTaskCallback(), { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); case 'reserved': return await client.userTasks.onUserTaskReserved(userTaskCallback(), { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); case 'reservation-canceled': return await client.userTasks.onUserTaskReservationCanceled(userTaskCallback(), { identity: currentIdentity, + }).catch((error) => { + node.error(error); }); default: console.error('no such event: ' + config.eventtype); @@ -79,7 +87,7 @@ module.exports = function (RED) { currentIdentity = identity; subscription = subscribe(); - }); + }) node.on('close', async () => { if (node.engine && node.engine.engineClient && client) {