fix: remove redundant step

This commit is contained in:
David Nguyen
2025-11-24 19:33:56 +11:00
parent 7a55abadaf
commit 8083e54625

View File

@ -22,53 +22,51 @@ export const run = async ({
const { webhookUrl: url, secret } = webhook; const { webhookUrl: url, secret } = webhook;
await io.runTask('execute-webhook', async () => { const payloadData = {
const payloadData = { event,
event, payload: data,
payload: data, createdAt: new Date().toISOString(),
createdAt: new Date().toISOString(), webhookEndpoint: url,
webhookEndpoint: url, };
};
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
body: JSON.stringify(payloadData), body: JSON.stringify(payloadData),
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Documenso-Secret': secret ?? '', 'X-Documenso-Secret': secret ?? '',
}, },
});
const body = await response.text();
let responseBody: Prisma.InputJsonValue | Prisma.JsonNullValueInput = Prisma.JsonNull;
try {
responseBody = JSON.parse(body);
} catch (err) {
responseBody = body;
}
await prisma.webhookCall.create({
data: {
url,
event,
status: response.ok ? WebhookCallStatus.SUCCESS : WebhookCallStatus.FAILED,
requestBody: payloadData as Prisma.InputJsonValue,
responseCode: response.status,
responseBody,
responseHeaders: Object.fromEntries(response.headers.entries()),
webhookId: webhook.id,
},
});
if (!response.ok) {
throw new Error(`Webhook execution failed with status ${response.status}`);
}
return {
success: response.ok,
status: response.status,
};
}); });
const body = await response.text();
let responseBody: Prisma.InputJsonValue | Prisma.JsonNullValueInput = Prisma.JsonNull;
try {
responseBody = JSON.parse(body);
} catch (err) {
responseBody = body;
}
await prisma.webhookCall.create({
data: {
url,
event,
status: response.ok ? WebhookCallStatus.SUCCESS : WebhookCallStatus.FAILED,
requestBody: payloadData as Prisma.InputJsonValue,
responseCode: response.status,
responseBody,
responseHeaders: Object.fromEntries(response.headers.entries()),
webhookId: webhook.id,
},
});
if (!response.ok) {
throw new Error(`Webhook execution failed with status ${response.status}`);
}
return {
success: response.ok,
status: response.status,
};
}; };