mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-23 02:21:42 -08:00
fix(EmailReadImap Node): Improve error handling (#3465)
This commit is contained in:
parent
c341b45396
commit
3806d6355d
|
@ -186,6 +186,8 @@ export class EmailReadImap implements INodeType {
|
||||||
const staticData = this.getWorkflowStaticData('node');
|
const staticData = this.getWorkflowStaticData('node');
|
||||||
Logger.debug('Loaded static data for node "EmailReadImap"', {staticData});
|
Logger.debug('Loaded static data for node "EmailReadImap"', {staticData});
|
||||||
|
|
||||||
|
let connection: ImapSimple;
|
||||||
|
|
||||||
// Returns the email text
|
// Returns the email text
|
||||||
const getText = async (parts: any[], message: Message, subtype: string) => { // tslint:disable-line:no-any
|
const getText = async (parts: any[], message: Message, subtype: string) => { // tslint:disable-line:no-any
|
||||||
if (!message.attributes.struct) {
|
if (!message.attributes.struct) {
|
||||||
|
@ -440,19 +442,29 @@ export class EmailReadImap implements INodeType {
|
||||||
// Connect to the IMAP server and open the mailbox
|
// Connect to the IMAP server and open the mailbox
|
||||||
// that we get informed whenever a new email arrives
|
// that we get informed whenever a new email arrives
|
||||||
return imapConnect(config).then(async conn => {
|
return imapConnect(config).then(async conn => {
|
||||||
conn.on('error', async err => {
|
conn.on('error', async error => {
|
||||||
if (err.code.toUpperCase() === 'ECONNRESET') {
|
const errorCode = error.code.toUpperCase();
|
||||||
Logger.verbose('IMAP connection was reset - reconnecting.');
|
if (['ECONNRESET', 'EPIPE'].includes(errorCode)) {
|
||||||
connection = await establishConnection();
|
Logger.verbose(`IMAP connection was reset (${errorCode}) - reconnecting.`, { error });
|
||||||
await connection.openBox(mailbox);
|
try {
|
||||||
|
connection = await establishConnection();
|
||||||
|
await connection.openBox(mailbox);
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error('IMAP reconnect did fail', { error: e });
|
||||||
|
// If something goes wrong we want to run emitError
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Logger.error('Email Read Imap node encountered a connection error', { error });
|
||||||
}
|
}
|
||||||
throw err;
|
|
||||||
|
this.emitError(error);
|
||||||
});
|
});
|
||||||
return conn;
|
return conn;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let connection: ImapSimple = await establishConnection();
|
connection = await establishConnection();
|
||||||
|
|
||||||
await connection.openBox(mailbox);
|
await connection.openBox(mailbox);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue