mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Expand error message for unknown webhook request (#15178)
This commit is contained in:
@@ -50,4 +50,8 @@ export class WebhookEntity {
|
||||
get isDynamic() {
|
||||
return this.webhookPath.split('/').some((s) => s.startsWith(':'));
|
||||
}
|
||||
|
||||
display() {
|
||||
return `${this.method} ${this.webhookPath}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user