mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(EmailReadImap Node): Fix issue that crashed process if node was configured wrong (#3079)
* 🐛 Fix issue that IMAP node can crash n8n * 👕 Fix lint issue
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { ITriggerFunctions } from 'n8n-core';
|
||||
import {
|
||||
createDeferredPromise,
|
||||
IBinaryData,
|
||||
IBinaryKeyData,
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
LoggerProxy,
|
||||
LoggerProxy as Logger,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
@@ -25,10 +27,6 @@ import {
|
||||
|
||||
import * as lodash from 'lodash';
|
||||
|
||||
import {
|
||||
LoggerProxy as Logger
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class EmailReadImap implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'EmailReadImap',
|
||||
@@ -377,6 +375,8 @@ export class EmailReadImap implements INodeType {
|
||||
return newEmails;
|
||||
};
|
||||
|
||||
const returnedPromise: IDeferredPromise<void> | undefined = await createDeferredPromise<void>();
|
||||
|
||||
const establishConnection = (): Promise<ImapSimple> => {
|
||||
|
||||
let searchCriteria = [
|
||||
@@ -425,7 +425,11 @@ export class EmailReadImap implements INodeType {
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('Email Read Imap node encountered an error fetching new emails', { error });
|
||||
throw error;
|
||||
// Wait with resolving till the returnedPromise got resolved, else n8n will be unhappy
|
||||
// if it receives an error before the workflow got activated
|
||||
returnedPromise.promise().then(() => {
|
||||
this.emitError(error as Error);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -475,10 +479,12 @@ export class EmailReadImap implements INodeType {
|
||||
await connection.end();
|
||||
}
|
||||
|
||||
// Resolve returned-promise so that waiting errors can be emitted
|
||||
returnedPromise.resolve();
|
||||
|
||||
return {
|
||||
closeFunction,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user