From 85e9c72acab3d183eca90385db36222e9df78172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 8 Nov 2024 14:44:36 +0100 Subject: [PATCH] Check using `event.error.code` --- packages/@n8n/task-runner/src/task-runner.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/@n8n/task-runner/src/task-runner.ts b/packages/@n8n/task-runner/src/task-runner.ts index 7fea7869e2..d1bf8a6d71 100644 --- a/packages/@n8n/task-runner/src/task-runner.ts +++ b/packages/@n8n/task-runner/src/task-runner.ts @@ -1,4 +1,4 @@ -import { ApplicationError } from 'n8n-workflow'; +import { ApplicationError, ensureError } from 'n8n-workflow'; import { nanoid } from 'nanoid'; import { type MessageEvent, WebSocket } from 'ws'; @@ -89,15 +89,21 @@ export abstract class TaskRunner { maxPayload: opts.maxPayloadSize, }); - this.ws.addEventListener('error', (error) => { - if (error.message?.includes('ECONNREFUSED') || error.message?.includes('ENOTFOUND')) { + this.ws.addEventListener('error', (event) => { + const error = ensureError(event.error); + + if ( + 'code' in error && + typeof error.code === 'string' && + ['ECONNREFUSED', 'ENOTFOUND'].some((code) => code === error.code) + ) { console.error( `Error: Failed to connect to n8n. Please ensure n8n is reachable at: ${opts.n8nUri}`, ); process.exit(1); } else { console.error(`Error: Failed to connect to n8n at ${opts.n8nUri}`); - console.error('Details:', error.message || 'Unknown error'); + console.error('Details:', event.message || 'Unknown error'); } }); this.ws.addEventListener('message', this.receiveMessage);