Skip to content

Commit

Permalink
fix: Fix application crashing when webhook is unavailable (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-sizov authored Jul 15, 2024
1 parent 67d1b1c commit 6052f89
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions server/api/helpers/utils/send-webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,22 @@ async function sendWebhook(webhook, event, data, user) {
user: sails.helpers.utils.jsonifyRecord(user),
});

const response = await fetch(webhook.url, {
headers,
body,
method: 'POST',
});
try {
const response = await fetch(webhook.url, {
headers,
body,
method: 'POST',
});

if (!response.ok) {
const message = await response.text();
if (!response.ok) {
const message = await response.text();

sails.log.error(
`Webhook ${webhook.url} failed with status ${response.status} and message: ${message}`,
);
sails.log.error(
`Webhook ${webhook.url} failed with status ${response.status} and message: ${message}`,
);
}
} catch (e) {
sails.log.error(`Webhook ${webhook.url} failed with error message: ${e.message}`);
}
}

Expand Down

0 comments on commit 6052f89

Please sign in to comment.