Skip to content

Commit

Permalink
Merge pull request #453 from sinamics/async-webhhook
Browse files Browse the repository at this point in the history
Improve webhook to send http request async
  • Loading branch information
sinamics committed Jun 28, 2024
2 parents 7a3e36d + 5ab7439 commit d898e89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ FROM base AS deps
WORKDIR /app

# Install Prisma Client - remove if not using Prisma
RUN npx prisma generate
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
COPY prisma ./
RUN npx prisma generate

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
Expand Down
28 changes: 15 additions & 13 deletions src/utils/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ export const sendWebhook = async <T extends HookBase>(data: T): Promise<void> =>

for (const webhook of webhookData) {
if ((webhook.eventTypes as string[]).includes(data.hookType)) {
try {
const response = await fetch(webhook.url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
(async () => {
try {
const response = await fetch(webhook.url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error(
`Failed to send webhook: ${response.status} ${response.statusText}`,
);
if (!response.ok) {
console.error(
`Failed to send webhook: ${response.status} ${response.statusText}`,
);
}
} catch (error) {
console.error(`Error sending webhooks: ${error.message}`);
}
} catch (error) {
throw new Error(`Error sending webhook: ${error.message}`);
}
})();
}
}
};

0 comments on commit d898e89

Please sign in to comment.