mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(core): Skip sending webhook activation errors to Sentry (no-changelog) (#7171)
This commit is contained in:
parent
07d072c28f
commit
ebce6fe1b0
|
@ -6,7 +6,7 @@ import type {
|
||||||
WorkflowActivateMode,
|
WorkflowActivateMode,
|
||||||
WorkflowExecuteMode,
|
WorkflowExecuteMode,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
import { WebhookPathAlreadyTakenError } from 'n8n-workflow';
|
||||||
import * as NodeExecuteFunctions from 'n8n-core';
|
import * as NodeExecuteFunctions from 'n8n-core';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
|
@ -46,9 +46,7 @@ export class ActiveWebhooks {
|
||||||
|
|
||||||
// check that there is not a webhook already registered with that path/method
|
// check that there is not a webhook already registered with that path/method
|
||||||
if (this.webhookUrls[webhookKey] && !webhookData.webhookId) {
|
if (this.webhookUrls[webhookKey] && !webhookData.webhookId) {
|
||||||
throw new Error(
|
throw new WebhookPathAlreadyTakenError(webhookData.node);
|
||||||
`The URL path that the "${webhookData.node}" node uses is already taken. Please change it to something else.`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.workflowWebhooks[webhookData.workflowId] === undefined) {
|
if (this.workflowWebhooks[webhookData.workflowId] === undefined) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import {
|
||||||
WorkflowActivationError,
|
WorkflowActivationError,
|
||||||
LoggerProxy as Logger,
|
LoggerProxy as Logger,
|
||||||
ErrorReporterProxy as ErrorReporter,
|
ErrorReporterProxy as ErrorReporter,
|
||||||
|
WebhookPathAlreadyTakenError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import type express from 'express';
|
import type express from 'express';
|
||||||
|
@ -428,11 +429,8 @@ export class ActiveWorkflowRunner implements IWebhookManager {
|
||||||
// if it's a workflow from the the insert
|
// if it's a workflow from the the insert
|
||||||
// TODO check if there is standard error code for duplicate key violation that works
|
// TODO check if there is standard error code for duplicate key violation that works
|
||||||
// with all databases
|
// with all databases
|
||||||
if (error.name === 'QueryFailedError') {
|
if (error instanceof Error && error.name === 'QueryFailedError') {
|
||||||
error = new Error(
|
error = new WebhookPathAlreadyTakenError(webhook.node, error);
|
||||||
`The URL path that the "${webhook.node}" node uses is already taken. Please change it to something else.`,
|
|
||||||
{ cause: error },
|
|
||||||
);
|
|
||||||
} else if (error.detail) {
|
} else if (error.detail) {
|
||||||
// it's a error running the webhook methods (checkExists, create)
|
// it's a error running the webhook methods (checkExists, create)
|
||||||
error.message = error.detail;
|
error.message = error.detail;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import { ErrorReporterProxy, NodeError } from 'n8n-workflow';
|
import { ErrorReporterProxy, ExecutionBaseError } from 'n8n-workflow';
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ export const initErrorHandling = async () => {
|
||||||
|
|
||||||
const seenErrors = new Set<string>();
|
const seenErrors = new Set<string>();
|
||||||
addGlobalEventProcessor((event, { originalException }) => {
|
addGlobalEventProcessor((event, { originalException }) => {
|
||||||
if (originalException instanceof NodeError && originalException.severity === 'warning')
|
if (originalException instanceof ExecutionBaseError && originalException.severity === 'warning')
|
||||||
return null;
|
return null;
|
||||||
if (!event.exception) return null;
|
if (!event.exception) return null;
|
||||||
const eventHash = createHash('sha1').update(JSON.stringify(event.exception)).digest('base64');
|
const eventHash = createHash('sha1').update(JSON.stringify(event.exception)).digest('base64');
|
||||||
|
|
|
@ -104,7 +104,7 @@ const STATUS_CODE_MESSAGES: IStatusCodeMessages = {
|
||||||
const UNKNOWN_ERROR_MESSAGE = 'UNKNOWN ERROR - check the detailed error for more information';
|
const UNKNOWN_ERROR_MESSAGE = 'UNKNOWN ERROR - check the detailed error for more information';
|
||||||
const UNKNOWN_ERROR_MESSAGE_CRED = 'UNKNOWN ERROR';
|
const UNKNOWN_ERROR_MESSAGE_CRED = 'UNKNOWN ERROR';
|
||||||
|
|
||||||
type Severity = 'warning' | 'error';
|
export type Severity = 'warning' | 'error';
|
||||||
|
|
||||||
interface ExecutionBaseErrorOptions {
|
interface ExecutionBaseErrorOptions {
|
||||||
cause?: Error | JsonObject;
|
cause?: Error | JsonObject;
|
||||||
|
@ -136,6 +136,8 @@ export abstract class ExecutionBaseError extends Error {
|
||||||
|
|
||||||
lineNumber: number | undefined;
|
lineNumber: number | undefined;
|
||||||
|
|
||||||
|
severity: Severity = 'error';
|
||||||
|
|
||||||
constructor(message: string, { cause }: ExecutionBaseErrorOptions) {
|
constructor(message: string, { cause }: ExecutionBaseErrorOptions) {
|
||||||
const options = cause instanceof Error ? { cause } : {};
|
const options = cause instanceof Error ? { cause } : {};
|
||||||
super(message, options);
|
super(message, options);
|
||||||
|
@ -171,8 +173,6 @@ export abstract class ExecutionBaseError extends Error {
|
||||||
export abstract class NodeError extends ExecutionBaseError {
|
export abstract class NodeError extends ExecutionBaseError {
|
||||||
node: INode;
|
node: INode;
|
||||||
|
|
||||||
severity: Severity = 'error';
|
|
||||||
|
|
||||||
constructor(node: INode, error: Error | JsonObject) {
|
constructor(node: INode, error: Error | JsonObject) {
|
||||||
const message = error instanceof Error ? error.message : '';
|
const message = error instanceof Error ? error.message : '';
|
||||||
super(message, { cause: error });
|
super(message, { cause: error });
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import type { INode } from './Interfaces';
|
import type { INode } from './Interfaces';
|
||||||
import { ExecutionBaseError } from './NodeErrors';
|
import { ExecutionBaseError, type Severity } from './NodeErrors';
|
||||||
|
|
||||||
interface WorkflowActivationErrorOptions {
|
interface WorkflowActivationErrorOptions {
|
||||||
cause?: Error;
|
cause?: Error;
|
||||||
node?: INode;
|
node?: INode;
|
||||||
|
severity?: Severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +13,7 @@ interface WorkflowActivationErrorOptions {
|
||||||
export class WorkflowActivationError extends ExecutionBaseError {
|
export class WorkflowActivationError extends ExecutionBaseError {
|
||||||
node: INode | undefined;
|
node: INode | undefined;
|
||||||
|
|
||||||
constructor(message: string, { cause, node }: WorkflowActivationErrorOptions) {
|
constructor(message: string, { cause, node, severity }: WorkflowActivationErrorOptions) {
|
||||||
let error = cause as Error;
|
let error = cause as Error;
|
||||||
if (cause instanceof ExecutionBaseError) {
|
if (cause instanceof ExecutionBaseError) {
|
||||||
error = new Error(cause.message);
|
error = new Error(cause.message);
|
||||||
|
@ -23,5 +24,15 @@ export class WorkflowActivationError extends ExecutionBaseError {
|
||||||
super(message, { cause: error });
|
super(message, { cause: error });
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
if (severity) this.severity = severity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WebhookPathAlreadyTakenError extends WorkflowActivationError {
|
||||||
|
constructor(nodeName: string, cause?: Error) {
|
||||||
|
super(
|
||||||
|
`The URL path that the "${nodeName}" node uses is already taken. Please change it to something else.`,
|
||||||
|
{ severity: 'warning', cause },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue