mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 21:51:40 +10:00
fix: remove redundant step
This commit is contained in:
@ -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,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user