mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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() {
|
get isDynamic() {
|
||||||
return this.webhookPath.split('/').some((s) => s.startsWith(':'));
|
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 { Logger } from 'n8n-core';
|
||||||
import { ensureError, type IHttpRequestMethods } from 'n8n-workflow';
|
import { ensureError, type IHttpRequestMethods } from 'n8n-workflow';
|
||||||
|
|
||||||
|
import { WebhookNotFoundError } from '@/errors/response-errors/webhook-not-found.error';
|
||||||
import * as ResponseHelper from '@/response-helper';
|
import * as ResponseHelper from '@/response-helper';
|
||||||
import type {
|
import type {
|
||||||
IWebhookManager,
|
IWebhookManager,
|
||||||
@@ -10,6 +11,8 @@ import type {
|
|||||||
WebhookRequest,
|
WebhookRequest,
|
||||||
} from '@/webhooks/webhook.types';
|
} from '@/webhooks/webhook.types';
|
||||||
|
|
||||||
|
import { WebhookService } from './webhook.service';
|
||||||
|
|
||||||
const WEBHOOK_METHODS: IHttpRequestMethods[] = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'];
|
const WEBHOOK_METHODS: IHttpRequestMethods[] = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'];
|
||||||
|
|
||||||
class WebhookRequestHandler {
|
class WebhookRequestHandler {
|
||||||
@@ -56,10 +59,20 @@ class WebhookRequestHandler {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = ensureError(e);
|
const error = ensureError(e);
|
||||||
Container.get(Logger).debug(
|
|
||||||
`Error in handling webhook request ${req.method} ${req.path}: ${error.message}`,
|
const logger = Container.get(Logger);
|
||||||
{ stacktrace: error.stack },
|
|
||||||
);
|
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);
|
return ResponseHelper.sendErrorResponse(res, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ export class WebhookService {
|
|||||||
void this.cacheService.setMany(allWebhooks.map((w) => [w.cacheKey, w]));
|
void this.cacheService.setMany(allWebhooks.map((w) => [w.cacheKey, w]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findAll() {
|
||||||
|
return await this.webhookRepository.find();
|
||||||
|
}
|
||||||
|
|
||||||
private async findCached(method: Method, path: string) {
|
private async findCached(method: Method, path: string) {
|
||||||
const cacheKey = `webhook:${method}-${path}`;
|
const cacheKey = `webhook:${method}-${path}`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user