mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🎨 Centralize error throwing for encryption keys and credentials (#3105)
* Centralized error throwing for encryption key * Unifying the error message used by cli and core packages * Improvements to error messages to make it more DRY * Removed unnecessary throw * Throwing error when credential does not exist to simplify node behavior (#3112) Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -874,13 +874,7 @@ export async function requestOAuth2(
|
||||
oAuth2Options?: IOAuth2Options,
|
||||
isN8nRequest = false,
|
||||
) {
|
||||
const credentials = (await this.getCredentials(
|
||||
credentialsType,
|
||||
)) as ICredentialDataDecryptedObject;
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials were returned!');
|
||||
}
|
||||
const credentials = await this.getCredentials(credentialsType);
|
||||
|
||||
if (credentials.oauthTokenData === undefined) {
|
||||
throw new Error('OAuth credentials not connected!');
|
||||
@@ -997,9 +991,7 @@ export async function requestOAuth1(
|
||||
| IHttpRequestOptions,
|
||||
isN8nRequest = false,
|
||||
) {
|
||||
const credentials = (await this.getCredentials(
|
||||
credentialsType,
|
||||
)) as ICredentialDataDecryptedObject;
|
||||
const credentials = await this.getCredentials(credentialsType);
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials were returned!');
|
||||
@@ -1269,7 +1261,7 @@ export async function getCredentials(
|
||||
runIndex?: number,
|
||||
connectionInputData?: INodeExecutionData[],
|
||||
itemIndex?: number,
|
||||
): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
): Promise<ICredentialDataDecryptedObject> {
|
||||
// Get the NodeType as it has the information if the credentials are required
|
||||
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
|
||||
if (nodeType === undefined) {
|
||||
@@ -1309,8 +1301,8 @@ export async function getCredentials(
|
||||
node.parameters,
|
||||
)
|
||||
) {
|
||||
// Credentials should not be displayed so return undefined even if they would be defined
|
||||
return undefined;
|
||||
// Credentials should not be displayed even if they would be defined
|
||||
throw new NodeOperationError(node, 'Credentials not found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1327,15 +1319,15 @@ export async function getCredentials(
|
||||
throw new NodeOperationError(node, `Node does not have any credentials set for "${type}"!`);
|
||||
}
|
||||
} else {
|
||||
// Credentials are not required so resolve with undefined
|
||||
return undefined;
|
||||
// Credentials are not required
|
||||
throw new NodeOperationError(node, 'Node does not require credentials');
|
||||
}
|
||||
}
|
||||
|
||||
if (fullAccess && (!node.credentials || !node.credentials[type])) {
|
||||
// Make sure that fullAccess nodes still behave like before that if they
|
||||
// request access to credentials that are currently not set it returns undefined
|
||||
return undefined;
|
||||
throw new NodeOperationError(node, 'Credentials not found');
|
||||
}
|
||||
|
||||
let expressionResolveValues: ICredentialsExpressionResolveValues | undefined;
|
||||
@@ -1605,7 +1597,7 @@ export function getExecutePollFunctions(
|
||||
__emit: (data: INodeExecutionData[][]): void => {
|
||||
throw new Error('Overwrite NodeExecuteFunctions.getExecutePullFunctions.__emit function!');
|
||||
},
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(workflow, node, type, additionalData, mode);
|
||||
},
|
||||
getMode: (): WorkflowExecuteMode => {
|
||||
@@ -1759,7 +1751,7 @@ export function getExecuteTriggerFunctions(
|
||||
emitError: (error: Error): void => {
|
||||
throw new Error('Overwrite NodeExecuteFunctions.getExecuteTriggerFunctions.emit function!');
|
||||
},
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(workflow, node, type, additionalData, mode);
|
||||
},
|
||||
getNode: () => {
|
||||
@@ -1949,7 +1941,7 @@ export function getExecuteFunctions(
|
||||
async getCredentials(
|
||||
type: string,
|
||||
itemIndex?: number,
|
||||
): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(
|
||||
workflow,
|
||||
node,
|
||||
@@ -2193,7 +2185,7 @@ export function getExecuteSingleFunctions(
|
||||
getContext(type: string): IContextObject {
|
||||
return NodeHelpers.getContext(runExecutionData, type, node);
|
||||
},
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(
|
||||
workflow,
|
||||
node,
|
||||
@@ -2389,7 +2381,7 @@ export function getLoadOptionsFunctions(
|
||||
): ILoadOptionsFunctions {
|
||||
return ((workflow: Workflow, node: INode, path: string) => {
|
||||
const that = {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(workflow, node, type, additionalData, 'internal');
|
||||
},
|
||||
getCurrentNodeParameter: (
|
||||
@@ -2533,7 +2525,7 @@ export function getExecuteHookFunctions(
|
||||
): IHookFunctions {
|
||||
return ((workflow: Workflow, node: INode) => {
|
||||
const that = {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(workflow, node, type, additionalData, mode);
|
||||
},
|
||||
getMode: (): WorkflowExecuteMode => {
|
||||
@@ -2692,7 +2684,7 @@ export function getExecuteWebhookFunctions(
|
||||
}
|
||||
return additionalData.httpRequest.body;
|
||||
},
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
||||
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject> {
|
||||
return getCredentials(workflow, node, type, additionalData, mode);
|
||||
},
|
||||
getHeaderData(): object {
|
||||
|
||||
Reference in New Issue
Block a user