From d8e3739306cfc3b8cd88d1766e860547ecd49049 Mon Sep 17 00:00:00 2001 From: AlasDiablo <25723276+AlasDiablo@users.noreply.github.com> Date: Mon, 6 May 2024 13:50:44 +0200 Subject: [PATCH] fix: send an empty response to acknowledge the webhook call --- tdm-be/src/controller/webhook.ts | 6 ++++-- tdm-be/src/worker/enrichmentHook.ts | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tdm-be/src/controller/webhook.ts b/tdm-be/src/controller/webhook.ts index 43f143b..1211bc8 100644 --- a/tdm-be/src/controller/webhook.ts +++ b/tdm-be/src/controller/webhook.ts @@ -19,7 +19,8 @@ router.post( return; } - enrichmentHook.success(id); + enrichmentHook.success(id).then(undefined); + res.send(); }, (error) => { logger.error(error); @@ -39,7 +40,8 @@ router.post( return; } - enrichmentHook.failure(id); + enrichmentHook.failure(id).then(undefined); + res.send(); }, (error) => { logger.error(error); diff --git a/tdm-be/src/worker/enrichmentHook.ts b/tdm-be/src/worker/enrichmentHook.ts index 5415e9c..fd699ad 100644 --- a/tdm-be/src/worker/enrichmentHook.ts +++ b/tdm-be/src/worker/enrichmentHook.ts @@ -210,9 +210,10 @@ const enrichmentHookFailure = async (processingId: string) => { }; const catchEnrichmentHook = (enrichmentHook: { (processingId: string): Promise }) => { - return (processingId: string) => { - const enrichmentPromise = enrichmentHook(processingId); - enrichmentPromise.catch((e) => { + return async (processingId: string) => { + try { + await enrichmentHook(processingId); + } catch (e) { const message = 'Receive an un-catch error from enrichment hook'; error(processingId, 'Receive an un-catch error from enrichment hook'); crash(e, message, processingId); @@ -222,8 +223,10 @@ const catchEnrichmentHook = (enrichmentHook: { (processingId: string): Promise