Skip to content

Commit

Permalink
refactor(core): Stop reporting to Sentry credential-not-found error (…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Nov 9, 2023
1 parent 0468ded commit 16a1a92
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
INodeTypes,
IWorkflowExecuteAdditionalData,
ICredentialTestFunctions,
Severity,
} from 'n8n-workflow';
import {
ICredentialsHelper,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 16a1a92

Please sign in to comment.