mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
bug(EmailReadImap Node): Improve error handling (#2991)
* Fix: EmailReadImap unhandled promise rejection Related to #2091 (but only partially) See https://github.com/n8n-io/n8n/issues/2091#issuecomment-980010289 * Send errors from email read imap to logger Co-authored-by: Manuel [tennox] <2084639+tennox@users.noreply.github.com>
This commit is contained in:
parent
1b993e4022
commit
846e866daf
|
@ -7,6 +7,7 @@ import {
|
|||
INodeType,
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
LoggerProxy,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
@ -377,6 +378,18 @@ export class EmailReadImap implements INodeType {
|
|||
};
|
||||
|
||||
const establishConnection = (): Promise<ImapSimple> => {
|
||||
|
||||
let searchCriteria = [
|
||||
'UNSEEN',
|
||||
] as Array<string | string[]>;
|
||||
if (options.customEmailConfig !== undefined) {
|
||||
try {
|
||||
searchCriteria = JSON.parse(options.customEmailConfig as string);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(this.getNode(), `Custom email config is not valid JSON.`);
|
||||
}
|
||||
}
|
||||
|
||||
const config: ImapSimpleOptions = {
|
||||
imap: {
|
||||
user: credentials.user as string,
|
||||
|
@ -388,16 +401,6 @@ export class EmailReadImap implements INodeType {
|
|||
},
|
||||
onmail: async () => {
|
||||
if (connection) {
|
||||
let searchCriteria = [
|
||||
'UNSEEN',
|
||||
] as Array<string | string[]>;
|
||||
if (options.customEmailConfig !== undefined) {
|
||||
try {
|
||||
searchCriteria = JSON.parse(options.customEmailConfig as string);
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(this.getNode(), `Custom email config is not valid JSON.`);
|
||||
}
|
||||
}
|
||||
if (staticData.lastMessageUid !== undefined) {
|
||||
searchCriteria.push(['UID', `${staticData.lastMessageUid as number}:*`]);
|
||||
/**
|
||||
|
@ -415,10 +418,14 @@ export class EmailReadImap implements INodeType {
|
|||
Logger.debug('Querying for new messages on node "EmailReadImap"', {searchCriteria});
|
||||
}
|
||||
|
||||
const returnData = await getNewEmails(connection, searchCriteria);
|
||||
|
||||
if (returnData.length) {
|
||||
this.emit([returnData]);
|
||||
try {
|
||||
const returnData = await getNewEmails(connection, searchCriteria);
|
||||
if (returnData.length) {
|
||||
this.emit([returnData]);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('Email Read Imap node encountered an error fetching new emails', { error });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue