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,
IWorkflowExecuteAdditionalData,
ICredentialTestFunctions,
Severity,
} from 'n8n-workflow';
import {
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()
export class CredentialsHelper extends ICredentialsHelper {
constructor(
@ -257,17 +267,17 @@ export class CredentialsHelper extends ICredentialsHelper {
throw new Error(`Credential "${nodeCredential.name}" of type "${type}" has no ID.`);
}
const credential = userId
? await Db.collections.SharedCredentials.findOneOrFail({
relations: ['credentials'],
where: { credentials: { id: nodeCredential.id, type }, userId },
}).then((shared) => shared.credentials)
: await Db.collections.Credentials.findOneByOrFail({ id: nodeCredential.id, type });
let credential: CredentialsEntity;
if (!credential) {
throw new Error(
`Credential with ID "${nodeCredential.id}" does not exist for type "${type}".`,
);
try {
credential = userId
? await Db.collections.SharedCredentials.findOneOrFail({
relations: ['credentials'],
where: { credentials: { id: nodeCredential.id, type }, userId },
}).then((shared) => shared.credentials)
: await Db.collections.Credentials.findOneByOrFail({ id: nodeCredential.id, type });
} catch (error) {
throw new CredentialNotFoundError(nodeCredential.id, type);
}
return new Credentials(