diff --git a/packages/@n8n/db/src/entities/webhook-entity.ts b/packages/@n8n/db/src/entities/webhook-entity.ts index 26066b8379..1c0e213f83 100644 --- a/packages/@n8n/db/src/entities/webhook-entity.ts +++ b/packages/@n8n/db/src/entities/webhook-entity.ts @@ -50,4 +50,8 @@ export class WebhookEntity { get isDynamic() { return this.webhookPath.split('/').some((s) => s.startsWith(':')); } + + display() { + return `${this.method} ${this.webhookPath}`; + } } diff --git a/packages/cli/src/webhooks/webhook-request-handler.ts b/packages/cli/src/webhooks/webhook-request-handler.ts index 30e420e11f..936536498b 100644 --- a/packages/cli/src/webhooks/webhook-request-handler.ts +++ b/packages/cli/src/webhooks/webhook-request-handler.ts @@ -3,6 +3,7 @@ import type express from 'express'; import { Logger } from 'n8n-core'; import { ensureError, type IHttpRequestMethods } from 'n8n-workflow'; +import { WebhookNotFoundError } from '@/errors/response-errors/webhook-not-found.error'; import * as ResponseHelper from '@/response-helper'; import type { IWebhookManager, @@ -10,6 +11,8 @@ import type { WebhookRequest, } from '@/webhooks/webhook.types'; +import { WebhookService } from './webhook.service'; + const WEBHOOK_METHODS: IHttpRequestMethods[] = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT']; class WebhookRequestHandler { @@ -56,10 +59,20 @@ class WebhookRequestHandler { } } catch (e) { const error = ensureError(e); - Container.get(Logger).debug( - `Error in handling webhook request ${req.method} ${req.path}: ${error.message}`, - { stacktrace: error.stack }, - ); + + const logger = Container.get(Logger); + + if (e instanceof WebhookNotFoundError) { + const currentlyRegistered = await Container.get(WebhookService).findAll(); + logger.error(`Received request for unknown webhook: ${e.message}`, { + currentlyRegistered: currentlyRegistered.map((w) => w.display()), + }); + } else { + logger.error( + `Error in handling webhook request ${req.method} ${req.path}: ${error.message}`, + { stacktrace: error.stack }, + ); + } return ResponseHelper.sendErrorResponse(res, error); } diff --git a/packages/cli/src/webhooks/webhook.service.ts b/packages/cli/src/webhooks/webhook.service.ts index 026eece5c8..d306d897bc 100644 --- a/packages/cli/src/webhooks/webhook.service.ts +++ b/packages/cli/src/webhooks/webhook.service.ts @@ -38,6 +38,10 @@ export class WebhookService { void this.cacheService.setMany(allWebhooks.map((w) => [w.cacheKey, w])); } + async findAll() { + return await this.webhookRepository.find(); + } + private async findCached(method: Method, path: string) { const cacheKey = `webhook:${method}-${path}`;