refactor(core): Stop reporting to Sentry credential-not-found error (no-changelog) (#7665)

https://n8nio.sentry.io/issues/4528134408
This commit is contained in:
Iván Ovejero 2023-11-09 10:55:13 +01:00 committed by GitHub
parent 0468ded0db
commit 16a1a92f18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,7 @@ import type {
INodeTypes, INodeTypes,
IWorkflowExecuteAdditionalData, IWorkflowExecuteAdditionalData,
ICredentialTestFunctions, ICredentialTestFunctions,
Severity,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
ICredentialsHelper, ICredentialsHelper,
@ -85,6 +86,15 @@ const mockNodeTypes: INodeTypes = {
}, },
}; };
class CredentialNotFoundError extends Error {
severity: Severity;
constructor(credentialId: string, credentialType: string) {
super(`Credential with ID "${credentialId}" does not exist for type "${credentialType}".`);
this.severity = 'warning';
}
}
@Service() @Service()
export class CredentialsHelper extends ICredentialsHelper { export class CredentialsHelper extends ICredentialsHelper {
constructor( constructor(
@ -257,17 +267,17 @@ export class CredentialsHelper extends ICredentialsHelper {
throw new Error(`Credential "${nodeCredential.name}" of type "${type}" has no ID.`); throw new Error(`Credential "${nodeCredential.name}" of type "${type}" has no ID.`);
} }
const credential = userId let credential: CredentialsEntity;
try {
credential = userId
? await Db.collections.SharedCredentials.findOneOrFail({ ? await Db.collections.SharedCredentials.findOneOrFail({
relations: ['credentials'], relations: ['credentials'],
where: { credentials: { id: nodeCredential.id, type }, userId }, where: { credentials: { id: nodeCredential.id, type }, userId },
}).then((shared) => shared.credentials) }).then((shared) => shared.credentials)
: await Db.collections.Credentials.findOneByOrFail({ id: nodeCredential.id, type }); : await Db.collections.Credentials.findOneByOrFail({ id: nodeCredential.id, type });
} catch (error) {
if (!credential) { throw new CredentialNotFoundError(nodeCredential.id, type);
throw new Error(
`Credential with ID "${nodeCredential.id}" does not exist for type "${type}".`,
);
} }
return new Credentials( return new Credentials(