mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(core): Enrich inaccessible credential error (#8574)
Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
457cac4cf9
commit
5304b320c8
|
@ -1,6 +1,6 @@
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
import type { INode, Workflow } from 'n8n-workflow';
|
import type { INode, Workflow } from 'n8n-workflow';
|
||||||
import { NodeOperationError, WorkflowOperationError } from 'n8n-workflow';
|
import { CredentialAccessError, NodeOperationError, WorkflowOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import { License } from '@/License';
|
import { License } from '@/License';
|
||||||
|
@ -59,13 +59,10 @@ export class PermissionChecker {
|
||||||
if (inaccessibleCredIds.length === 0) return;
|
if (inaccessibleCredIds.length === 0) return;
|
||||||
|
|
||||||
// if disallowed, flag only first node using first inaccessible cred
|
// if disallowed, flag only first node using first inaccessible cred
|
||||||
|
const inaccessibleCredId = inaccessibleCredIds[0];
|
||||||
|
const nodeToFlag = credIdsToNodes[inaccessibleCredId][0];
|
||||||
|
|
||||||
const nodeToFlag = credIdsToNodes[inaccessibleCredIds[0]][0];
|
throw new CredentialAccessError(nodeToFlag, inaccessibleCredId, workflow);
|
||||||
|
|
||||||
throw new NodeOperationError(nodeToFlag, 'Node has no access to credential', {
|
|
||||||
description: 'Please recreate the credential or ask its owner to share it with you.',
|
|
||||||
level: 'warning',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkSubworkflowExecutePolicy(
|
async checkSubworkflowExecutePolicy(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Functionality, IDataObject, JsonObject } from '../../Interfaces';
|
import type { Functionality, IDataObject, JsonObject } from '../../Interfaces';
|
||||||
import { ApplicationError } from '../application.error';
|
import { ApplicationError, type ReportingOptions } from '../application.error';
|
||||||
|
|
||||||
interface ExecutionBaseErrorOptions {
|
interface ExecutionBaseErrorOptions extends ReportingOptions {
|
||||||
cause?: Error;
|
cause?: Error;
|
||||||
errorResponse?: JsonObject;
|
errorResponse?: JsonObject;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ export abstract class ExecutionBaseError extends ApplicationError {
|
||||||
|
|
||||||
functionality: Functionality = 'regular';
|
functionality: Functionality = 'regular';
|
||||||
|
|
||||||
constructor(message: string, { cause, errorResponse }: ExecutionBaseErrorOptions = {}) {
|
constructor(message: string, options: ExecutionBaseErrorOptions = {}) {
|
||||||
const options = cause instanceof Error ? { cause } : {};
|
|
||||||
super(message, options);
|
super(message, options);
|
||||||
|
|
||||||
this.name = this.constructor.name;
|
this.name = this.constructor.name;
|
||||||
this.timestamp = Date.now();
|
this.timestamp = Date.now();
|
||||||
|
|
||||||
|
const { cause, errorResponse } = options;
|
||||||
if (cause instanceof ExecutionBaseError) {
|
if (cause instanceof ExecutionBaseError) {
|
||||||
this.context = cause.context;
|
this.context = cause.context;
|
||||||
} else if (cause && !(cause instanceof Error)) {
|
} else if (cause && !(cause instanceof Error)) {
|
||||||
|
|
26
packages/workflow/src/errors/credential-access-error.ts
Normal file
26
packages/workflow/src/errors/credential-access-error.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import type { INode } from '@/Interfaces';
|
||||||
|
import { ExecutionBaseError } from './abstract/execution-base.error';
|
||||||
|
|
||||||
|
export class CredentialAccessError extends ExecutionBaseError {
|
||||||
|
override readonly description =
|
||||||
|
'Please recreate the credential or ask its owner to share it with you.';
|
||||||
|
|
||||||
|
override readonly level = 'warning';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
readonly node: INode,
|
||||||
|
credentialId: string,
|
||||||
|
workflow: { id: string; name?: string },
|
||||||
|
) {
|
||||||
|
super('Node has no access to credential', {
|
||||||
|
tags: {
|
||||||
|
nodeType: node.type,
|
||||||
|
},
|
||||||
|
extra: {
|
||||||
|
workflowId: workflow.id,
|
||||||
|
workflowName: workflow.name ?? '',
|
||||||
|
credentialId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
export { ApplicationError } from './application.error';
|
export { ApplicationError } from './application.error';
|
||||||
export { ExpressionError } from './expression.error';
|
export { ExpressionError } from './expression.error';
|
||||||
|
export { CredentialAccessError } from './credential-access-error';
|
||||||
export { NodeApiError } from './node-api.error';
|
export { NodeApiError } from './node-api.error';
|
||||||
export { NodeOperationError } from './node-operation.error';
|
export { NodeOperationError } from './node-operation.error';
|
||||||
export { NodeSslError } from './node-ssl.error';
|
export { NodeSslError } from './node-ssl.error';
|
||||||
|
|
Loading…
Reference in a new issue