mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
Check using event.error.code
This commit is contained in:
parent
1bd0a6e381
commit
85e9c72aca
|
@ -1,4 +1,4 @@
|
||||||
import { ApplicationError } from 'n8n-workflow';
|
import { ApplicationError, ensureError } from 'n8n-workflow';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { type MessageEvent, WebSocket } from 'ws';
|
import { type MessageEvent, WebSocket } from 'ws';
|
||||||
|
|
||||||
|
@ -89,15 +89,21 @@ export abstract class TaskRunner {
|
||||||
maxPayload: opts.maxPayloadSize,
|
maxPayload: opts.maxPayloadSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.ws.addEventListener('error', (error) => {
|
this.ws.addEventListener('error', (event) => {
|
||||||
if (error.message?.includes('ECONNREFUSED') || error.message?.includes('ENOTFOUND')) {
|
const error = ensureError(event.error);
|
||||||
|
|
||||||
|
if (
|
||||||
|
'code' in error &&
|
||||||
|
typeof error.code === 'string' &&
|
||||||
|
['ECONNREFUSED', 'ENOTFOUND'].some((code) => code === error.code)
|
||||||
|
) {
|
||||||
console.error(
|
console.error(
|
||||||
`Error: Failed to connect to n8n. Please ensure n8n is reachable at: ${opts.n8nUri}`,
|
`Error: Failed to connect to n8n. Please ensure n8n is reachable at: ${opts.n8nUri}`,
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.error(`Error: Failed to connect to n8n at ${opts.n8nUri}`);
|
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);
|
this.ws.addEventListener('message', this.receiveMessage);
|
||||||
|
|
Loading…
Reference in a new issue