Handle errors while revalidating

This commit is contained in:
DrMint 2024-07-28 22:32:58 +02:00
parent 39a0382318
commit 7feccde653
1 changed files with 7 additions and 1 deletions

View File

@ -7,12 +7,18 @@ import type { EndpointChange } from "src/shared/payload/webhooks";
export const webhookHandler = async (changes: EndpointChange[]) => { export const webhookHandler = async (changes: EndpointChange[]) => {
const index = meili.index(MeiliIndexes.DOCUMENT); const index = meili.index(MeiliIndexes.DOCUMENT);
console.log("[Webhook] Received the following message", changes);
const documents: MeiliDocument[] = []; const documents: MeiliDocument[] = [];
for (const change of changes) { for (const change of changes) {
await index.deleteDocuments({ await index.deleteDocuments({
filter: `endpointCalled = "${change.url}"`, filter: `endpointCalled = "${change.url}"`,
}); });
documents.push(...(await convertEndpointChangeToMeiliDocuments(change))); try {
documents.push(...(await convertEndpointChangeToMeiliDocuments(change)));
} catch (e) {
console.log("[Webhook] Failure to revalidate", change.url);
}
} }
console.log("[Webhook] Adding", documents.length, "documents to Meilisearch"); console.log("[Webhook] Adding", documents.length, "documents to Meilisearch");