Skip to content

Commit

Permalink
Merge pull request #36 from Inist-CNRS/fix/webhook-response
Browse files Browse the repository at this point in the history
Send an empty response to acknowledge the webhook call
  • Loading branch information
AlasDiablo authored May 13, 2024
2 parents ea85f70 + d8e3739 commit bdf9ef0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions tdm-be/src/controller/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ router.post(
return;
}

enrichmentHook.success(id);
enrichmentHook.success(id).then(undefined);
res.send();
},
(error) => {
logger.error(error);
Expand All @@ -39,7 +40,8 @@ router.post(
return;
}

enrichmentHook.failure(id);
enrichmentHook.failure(id).then(undefined);
res.send();
},
(error) => {
logger.error(error);
Expand Down
13 changes: 8 additions & 5 deletions tdm-be/src/worker/enrichmentHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ const enrichmentHookFailure = async (processingId: string) => {
};

const catchEnrichmentHook = (enrichmentHook: { (processingId: string): Promise<void> }) => {
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);
Expand All @@ -222,8 +223,10 @@ const catchEnrichmentHook = (enrichmentHook: { (processingId: string): Promise<v
return;
}
errorEmail(processing, ERROR_MESSAGE_ENRICHMENT_HOOK_UNEXPECTED_ERROR);
} catch (ignored) {}
});
} catch (ignored) {
/* empty */
}
}
};
};

Expand Down

0 comments on commit bdf9ef0

Please sign in to comment.