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:
Iván Ovejero 2024-02-21 13:04:30 +01:00 committed by GitHub
parent 457cac4cf9
commit 5304b320c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 11 deletions

View file

@ -1,6 +1,6 @@
import { Service } from 'typedi';
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 { License } from '@/License';
@ -59,13 +59,10 @@ export class PermissionChecker {
if (inaccessibleCredIds.length === 0) return;
// 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 NodeOperationError(nodeToFlag, 'Node has no access to credential', {
description: 'Please recreate the credential or ask its owner to share it with you.',
level: 'warning',
});
throw new CredentialAccessError(nodeToFlag, inaccessibleCredId, workflow);
}
async checkSubworkflowExecutePolicy(

View file

@ -1,7 +1,7 @@
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;
errorResponse?: JsonObject;
}
@ -21,13 +21,13 @@ export abstract class ExecutionBaseError extends ApplicationError {
functionality: Functionality = 'regular';
constructor(message: string, { cause, errorResponse }: ExecutionBaseErrorOptions = {}) {
const options = cause instanceof Error ? { cause } : {};
constructor(message: string, options: ExecutionBaseErrorOptions = {}) {
super(message, options);
this.name = this.constructor.name;
this.timestamp = Date.now();
const { cause, errorResponse } = options;
if (cause instanceof ExecutionBaseError) {
this.context = cause.context;
} else if (cause && !(cause instanceof Error)) {

View 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,
},
});
}
}

View file

@ -1,5 +1,6 @@
export { ApplicationError } from './application.error';
export { ExpressionError } from './expression.error';
export { CredentialAccessError } from './credential-access-error';
export { NodeApiError } from './node-api.error';
export { NodeOperationError } from './node-operation.error';
export { NodeSslError } from './node-ssl.error';