fix(core): Better error message in Webhook node when using the POST method

This commit is contained in:
Michael Kret
2023-05-02 17:27:05 +03:00
committed by GitHub
parent 5364a2dff3
commit a0dd17e115
4 changed files with 72 additions and 5 deletions

View File

@@ -58,3 +58,31 @@ export const separate = <T>(array: T[], test: (element: T) => boolean) => {
return [pass, fail];
};
export const webhookNotFoundErrorMessage = (
path: string,
httpMethod?: string,
webhookMethods?: string[],
) => {
let webhookPath = path;
if (httpMethod) {
webhookPath = `${httpMethod} ${webhookPath}`;
}
if (webhookMethods?.length && httpMethod) {
let methods = '';
if (webhookMethods.length === 1) {
methods = webhookMethods[0];
} else {
const lastMethod = webhookMethods.pop();
methods = `${webhookMethods.join(', ')} or ${lastMethod as string}`;
}
return `This webhook is not registered for ${httpMethod} requests. Did you mean to make a ${methods} request?`;
} else {
return `The requested webhook "${webhookPath}" is not registered.`;
}
};