Skip to content

Open-source status page, incident response and uptime monitoring

feat: using effect-ts to retry notification (#1652)

Thibault Le Ouayb086303a605c
diff --git a/apps/workflows/package.json b/apps/workflows/package.json
index c53ef502b..4eaab7080 100644
--- a/apps/workflows/package.json
+++ b/apps/workflows/package.json
@@ -29,6 +29,7 @@
"@openstatus/utils": "workspace:*",
"@upstash/qstash": "2.6.2",
"drizzle-orm": "0.44.4",
+ "effect": "3.19.12",
"hono": "4.5.3",
"limiter": "^3.0.0",
"zod": "3.25.76"
diff --git a/apps/workflows/src/checker/alerting.ts b/apps/workflows/src/checker/alerting.ts
index a4ea5c17f..28a856ed6 100644
--- a/apps/workflows/src/checker/alerting.ts
+++ b/apps/workflows/src/checker/alerting.ts
@@ -8,6 +8,7 @@ import {
import { getLogger } from "@logtape/logtape";
import type { Region } from "@openstatus/db/src/schema/constants";
+import { Effect, Schedule } from "effect";
import { checkerAudit } from "../utils/audit-log";
import { providerToFunction } from "./utils";
@@ -115,39 +116,80 @@ export const triggerNotifications = async ({
}
switch (notifType) {
case "alert":
- await providerToFunction[notif.notification.provider].sendAlert({
- monitor,
- notification: selectNotificationSchema.parse(notif.notification),
- statusCode,
- message,
- incidentId,
- cronTimestamp,
- region,
- latency,
- });
+ const alertResult = Effect.tryPromise({
+ try: () =>
+ providerToFunction[notif.notification.provider].sendAlert({
+ monitor,
+ notification: selectNotificationSchema.parse(notif.notification),
+ statusCode,
+ message,
+ incidentId,
+ cronTimestamp,
+ region,
+ latency,
+ }),
+
+ catch: (_unknown) =>
+ new Error(
+ `Failed sending notification via ${notif.notification.provider} for monitor ${monitorId}`,
+ ),
+ }).pipe(
+ Effect.retry({
+ times: 3,
+ schedule: Schedule.exponential("1000 millis"),
+ }),
+ );
+ await Effect.runPromise(alertResult).catch(console.error);
break;
case "recovery":
- await providerToFunction[notif.notification.provider].sendRecovery({
- monitor,
- notification: selectNotificationSchema.parse(notif.notification),
- statusCode,
- message,
- incidentId,
- cronTimestamp,
- region,
- latency,
- });
+ const recoveryResult = Effect.tryPromise({
+ try: () =>
+ providerToFunction[notif.notification.provider].sendRecovery({
+ monitor,
+ notification: selectNotificationSchema.parse(notif.notification),
+ statusCode,
+ message,
+ incidentId,
+ cronTimestamp,
+ region,
+ latency,
+ }),
+ catch: (_unknown) =>
+ new Error(
+ `Failed sending notification via ${notif.notification.provider} for monitor ${monitorId}`,
+ ),
+ }).pipe(
+ Effect.retry({
+ times: 3,
+ schedule: Schedule.exponential("1000 millis"),
+ }),
+ );
+ await Effect.runPromise(recoveryResult).catch(console.error);
break;
case "degraded":
- await providerToFunction[notif.notification.provider].sendDegraded({
- monitor,
- notification: selectNotificationSchema.parse(notif.notification),
- statusCode,
- message,
- cronTimestamp,
- region,
- latency,
- });
+ const degradedResult = Effect.tryPromise({
+ try: () =>
+ providerToFunction[notif.notification.provider].sendDegraded({
+ monitor,
+ notification: selectNotificationSchema.parse(notif.notification),
+ statusCode,
+ message,
+ incidentId,
+ cronTimestamp,
+ region,
+ latency,
+ }),
+ catch: (_unknown) =>
+ new Error(
+ `Failed sending notification via ${notif.notification.provider} for monitor ${monitorId}`,
+ ),
+ }).pipe(
+ Effect.retry({
+ times: 3,
+ schedule: Schedule.exponential("1000 millis"),
+ }),
+ );
+ await Effect.runPromise(degradedResult).catch(console.error);
break;
}
// ALPHA
@@ -162,7 +204,6 @@ export const triggerNotifications = async ({
notificationId: notif.notification.id,
},
});
- //
}
};
diff --git a/packages/emails/src/client.tsx b/packages/emails/src/client.tsx
index 88388ee94..9bc0d63ea 100644
--- a/packages/emails/src/client.tsx
+++ b/packages/emails/src/client.tsx
@@ -181,6 +181,7 @@ export class EmailClient {
throw result.error;
} catch (err) {
console.error(`Error sending monitor alert to ${req.to}`, err);
+ throw err;
}
}
diff --git a/packages/notifications/discord/src/index.test.ts b/packages/notifications/discord/src/index.test.ts
index bab388b10..cc9b47cb1 100644
--- a/packages/notifications/discord/src/index.test.ts
+++ b/packages/notifications/discord/src/index.test.ts
@@ -12,6 +12,7 @@ describe("Discord Notifications", () => {
let fetchMock: any = undefined;
beforeEach(() => {
+ // @ts-expect-error
fetchMock = spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve(new Response(null, { status: 200 })),
);
@@ -150,17 +151,15 @@ describe("Discord Notifications", () => {
const notification = selectNotificationSchema.parse(
createMockNotification(),
);
-
- // Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- cronTimestamp: Date.now(),
- });
-
- expect(fetchMock).toHaveBeenCalledTimes(1);
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
});
});
diff --git a/packages/notifications/discord/src/index.ts b/packages/notifications/discord/src/index.ts
index 43900cc82..65192b3f9 100644
--- a/packages/notifications/discord/src/index.ts
+++ b/packages/notifications/discord/src/index.ts
@@ -3,7 +3,7 @@ import { discordDataSchema } from "@openstatus/db/src/schema";
import type { Region } from "@openstatus/db/src/schema/constants";
const postToWebhook = async (content: string, webhookUrl: string) => {
- await fetch(webhookUrl, {
+ const res = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -15,6 +15,11 @@ const postToWebhook = async (content: string, webhookUrl: string) => {
username: "OpenStatus Notifications",
}),
});
+ if (!res.ok) {
+ throw new Error(
+ `Failed to send Discord webhook: ${res.status} ${res.statusText}`,
+ );
+ }
};
export const sendAlert = async ({
@@ -52,7 +57,7 @@ export const sendAlert = async ({
);
} catch (err) {
console.error(err);
- // Do something
+ throw err;
}
};
@@ -88,7 +93,7 @@ export const sendRecovery = async ({
);
} catch (err) {
console.error(err);
- // Do something
+ throw err;
}
};
@@ -124,7 +129,7 @@ export const sendDegraded = async ({
);
} catch (err) {
console.error(err);
- // Do something
+ throw err;
}
};
diff --git a/packages/notifications/discord/tsconfig.json b/packages/notifications/discord/tsconfig.json
index a8a8c9309..b4382e67e 100644
--- a/packages/notifications/discord/tsconfig.json
+++ b/packages/notifications/discord/tsconfig.json
@@ -1,4 +1,7 @@
{
"extends": "@openstatus/tsconfig/nextjs.json",
- "include": ["src", "*.ts"]
+ "include": ["src", "*.ts"],
+ "compilerOptions": {
+ "types": ["bun-types"]
+ }
}
diff --git a/packages/notifications/ntfy/src/index.test.ts b/packages/notifications/ntfy/src/index.test.ts
index 527b08c57..349614c41 100644
--- a/packages/notifications/ntfy/src/index.test.ts
+++ b/packages/notifications/ntfy/src/index.test.ts
@@ -7,6 +7,7 @@ describe("Ntfy Notifications", () => {
let fetchMock: any = undefined;
beforeEach(() => {
+ // @ts-expect-error
fetchMock = spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve(new Response(null, { status: 200 })),
);
@@ -244,14 +245,16 @@ describe("Ntfy Notifications", () => {
);
// Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- cronTimestamp: Date.now(),
- });
+ await expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
diff --git a/packages/notifications/ntfy/src/index.ts b/packages/notifications/ntfy/src/index.ts
index 51d18b78b..55698c872 100644
--- a/packages/notifications/ntfy/src/index.ts
+++ b/packages/notifications/ntfy/src/index.ts
@@ -35,17 +35,15 @@ export const sendAlert = async ({
? `${notificationData.ntfy.serverUrl}/${notificationData.ntfy.topic}`
: `https://ntfy.sh/${notificationData.ntfy.topic}`;
- try {
- await fetch(url, {
- method: "post",
- body,
- headers: {
- ...authorization,
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+ const res = await fetch(url, {
+ method: "post",
+ body,
+ headers: {
+ ...authorization,
+ },
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send alert notification: ${res.statusText}`);
}
};
@@ -79,17 +77,16 @@ export const sendRecovery = async ({
const url = notificationData.ntfy.serverUrl
? `${notificationData.ntfy.serverUrl}/${notificationData.ntfy.topic}`
: `https://ntfy.sh/${notificationData.ntfy.topic}`;
- try {
- await fetch(url, {
- method: "post",
- body,
- headers: {
- ...authorization,
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+
+ const res = await fetch(url, {
+ method: "post",
+ body,
+ headers: {
+ ...authorization,
+ },
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send recovery notification: ${res.statusText}`);
}
};
@@ -123,17 +120,15 @@ export const sendDegraded = async ({
? `${notificationData.ntfy.serverUrl}/${notificationData.ntfy.topic}`
: `https://ntfy.sh/${notificationData.ntfy.topic}`;
- try {
- await fetch(url, {
- method: "post",
- body,
- headers: {
- ...authorization,
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+ const res = await fetch(url, {
+ method: "post",
+ body,
+ headers: {
+ ...authorization,
+ },
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send degraded notification: ${res.statusText}`);
}
};
diff --git a/packages/notifications/ntfy/tsconfig.json b/packages/notifications/ntfy/tsconfig.json
index a8a8c9309..b4382e67e 100644
--- a/packages/notifications/ntfy/tsconfig.json
+++ b/packages/notifications/ntfy/tsconfig.json
@@ -1,4 +1,7 @@
{
"extends": "@openstatus/tsconfig/nextjs.json",
- "include": ["src", "*.ts"]
+ "include": ["src", "*.ts"],
+ "compilerOptions": {
+ "types": ["bun-types"]
+ }
}
diff --git a/packages/notifications/opsgenie/src/index.test.ts b/packages/notifications/opsgenie/src/index.test.ts
index 6e93bf1ab..bfa3cf0af 100644
--- a/packages/notifications/opsgenie/src/index.test.ts
+++ b/packages/notifications/opsgenie/src/index.test.ts
@@ -7,6 +7,7 @@ describe("OpsGenie Notifications", () => {
let fetchMock: any = undefined;
beforeEach(() => {
+ // @ts-expect-error
fetchMock = spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve(new Response(null, { status: 200 })),
);
@@ -130,16 +131,16 @@ describe("OpsGenie Notifications", () => {
createMockNotification(),
);
- // Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- incidentId: "incident-123",
- cronTimestamp: Date.now(),
- });
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
diff --git a/packages/notifications/opsgenie/src/index.ts b/packages/notifications/opsgenie/src/index.ts
index d950860e1..8c8bd8008 100644
--- a/packages/notifications/opsgenie/src/index.ts
+++ b/packages/notifications/opsgenie/src/index.ts
@@ -37,18 +37,19 @@ export const sendAlert = async ({
opsgenie.region === "eu"
? "https://api.eu.opsgenie.com/v2/alerts"
: "https://api.opsgenie.com/v2/alerts";
- try {
- await fetch(url, {
- method: "POST",
- body: JSON.stringify(event),
- headers: {
- "Content-Type": "application/json",
- Authorization: `GenieKey ${opsgenie.apiKey}`,
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+
+ const res = await fetch(url, {
+ method: "POST",
+ body: JSON.stringify(event),
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `GenieKey ${opsgenie.apiKey}`,
+ },
+ });
+ if (!res.ok) {
+ throw new Error(
+ `Failed to send OpsGenie alert: ${res.status} ${res.statusText}`,
+ );
}
};
@@ -86,20 +87,18 @@ export const sendDegraded = async ({
opsgenie.region === "eu"
? "https://api.eu.opsgenie.com/v2/alerts"
: "https://api.opsgenie.com/v2/alerts";
- try {
- await fetch(url, {
- method: "POST",
- body: JSON.stringify(event),
- headers: {
- "Content-Type": "application/json",
- Authorization: `GenieKey ${opsgenie.apiKey}`,
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
-
- // Do something
+ const res = await fetch(url, {
+ method: "POST",
+ body: JSON.stringify(event),
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `GenieKey ${opsgenie.apiKey}`,
+ },
+ });
+ if (!res.ok) {
+ throw new Error(
+ `Failed to send OpsGenie degraded alert: ${res.status} ${res.statusText}`,
+ );
}
};
diff --git a/packages/notifications/opsgenie/tsconfig.json b/packages/notifications/opsgenie/tsconfig.json
index a8a8c9309..b4382e67e 100644
--- a/packages/notifications/opsgenie/tsconfig.json
+++ b/packages/notifications/opsgenie/tsconfig.json
@@ -1,4 +1,7 @@
{
"extends": "@openstatus/tsconfig/nextjs.json",
- "include": ["src", "*.ts"]
+ "include": ["src", "*.ts"],
+ "compilerOptions": {
+ "types": ["bun-types"]
+ }
}
diff --git a/packages/notifications/pagerduty/src/index.test.ts b/packages/notifications/pagerduty/src/index.test.ts
index 2af8e7d19..edcf64725 100644
--- a/packages/notifications/pagerduty/src/index.test.ts
+++ b/packages/notifications/pagerduty/src/index.test.ts
@@ -190,16 +190,16 @@ describe("PagerDuty Notifications", () => {
createMockNotification(),
);
- // Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- incidentId: "incident-123",
- cronTimestamp: Date.now(),
- });
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
diff --git a/packages/notifications/pagerduty/src/index.ts b/packages/notifications/pagerduty/src/index.ts
index d92375fa9..e7bf3b89f 100644
--- a/packages/notifications/pagerduty/src/index.ts
+++ b/packages/notifications/pagerduty/src/index.ts
@@ -34,33 +34,32 @@ export const sendAlert = async ({
const { name } = monitor;
- try {
- for await (const integrationKey of notificationData.integration_keys) {
- // biome-ignore lint/correctness/noUnusedVariables: <explanation>
- const { integration_key, type } = integrationKey;
- const event = triggerEventPayloadSchema.parse({
- routing_key: integration_key,
- dedup_key: `${monitor.id}}-${incidentId}`,
- event_action: "trigger",
- payload: {
- summary: `${name} is down`,
- source: "Open Status",
- severity: "error",
- timestamp: new Date(cronTimestamp).toISOString(),
- custom_details: {
- statusCode,
- message,
- },
+ for await (const integrationKey of notificationData.integration_keys) {
+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>
+ const { integration_key, type } = integrationKey;
+ const event = triggerEventPayloadSchema.parse({
+ routing_key: integration_key,
+ dedup_key: `${monitor.id}}-${incidentId}`,
+ event_action: "trigger",
+ payload: {
+ summary: `${name} is down`,
+ source: "Open Status",
+ severity: "error",
+ timestamp: new Date(cronTimestamp).toISOString(),
+ custom_details: {
+ statusCode,
+ message,
},
- });
- await fetch("https://events.pagerduty.com/v2/enqueue", {
- method: "POST",
- body: JSON.stringify(event),
- });
+ },
+ });
+ const res = await fetch("https://events.pagerduty.com/v2/enqueue", {
+ method: "POST",
+ body: JSON.stringify(event),
+ });
+ if (!res.ok) {
+ console.log(`Failed to send alert notification: ${res.statusText}`);
+ throw new Error("Failed to send alert notification");
}
- } catch (err) {
- console.log(err);
- // Do something
}
};
@@ -84,35 +83,34 @@ export const sendDegraded = async ({
const notificationData = PagerDutySchema.parse(JSON.parse(data.pagerduty));
const { name } = monitor;
- try {
- for await (const integrationKey of notificationData.integration_keys) {
- // biome-ignore lint/correctness/noUnusedVariables: <explanation>
- const { integration_key, type } = integrationKey;
+ for await (const integrationKey of notificationData.integration_keys) {
+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>
+ const { integration_key, type } = integrationKey;
- const event = triggerEventPayloadSchema.parse({
- routing_key: integration_key,
- dedup_key: `${monitor.id}}`,
- event_action: "trigger",
- payload: {
- summary: `${name} is degraded`,
- source: "Open Status",
- severity: "warning",
- timestamp: new Date().toISOString(),
- custom_details: {
- statusCode,
- message,
- },
+ const event = triggerEventPayloadSchema.parse({
+ routing_key: integration_key,
+ dedup_key: `${monitor.id}}`,
+ event_action: "trigger",
+ payload: {
+ summary: `${name} is degraded`,
+ source: "Open Status",
+ severity: "warning",
+ timestamp: new Date().toISOString(),
+ custom_details: {
+ statusCode,
+ message,
},
- });
+ },
+ });
- await fetch("https://events.pagerduty.com/v2/enqueue", {
- method: "POST",
- body: JSON.stringify(event),
- });
+ const res = await fetch("https://events.pagerduty.com/v2/enqueue", {
+ method: "POST",
+ body: JSON.stringify(event),
+ });
+ if (!res.ok) {
+ console.log(`Failed to send alert notification: ${res.statusText}`);
+ throw new Error("Failed to send alert notification");
}
- } catch (err) {
- console.log(err);
- // Do something
}
};
@@ -138,21 +136,20 @@ export const sendRecovery = async ({
const notificationData = PagerDutySchema.parse(JSON.parse(data.pagerduty));
- try {
- for await (const integrationKey of notificationData.integration_keys) {
- const event = resolveEventPayloadSchema.parse({
- routing_key: integrationKey.integration_key,
- dedup_key: `${monitor.id}}-${incidentId}`,
- event_action: "resolve",
- });
- await fetch("https://events.pagerduty.com/v2/enqueue", {
- method: "POST",
- body: JSON.stringify(event),
- });
+ for await (const integrationKey of notificationData.integration_keys) {
+ const event = resolveEventPayloadSchema.parse({
+ routing_key: integrationKey.integration_key,
+ dedup_key: `${monitor.id}}-${incidentId}`,
+ event_action: "resolve",
+ });
+ const res = await fetch("https://events.pagerduty.com/v2/enqueue", {
+ method: "POST",
+ body: JSON.stringify(event),
+ });
+ if (!res.ok) {
+ console.log(`Failed to send alert notification: ${res.statusText}`);
+ throw new Error("Failed to send alert notification");
}
- } catch (err) {
- console.log(err);
- // Do something
}
};
diff --git a/packages/notifications/slack/src/index.test.ts b/packages/notifications/slack/src/index.test.ts
index 3ee8a3e81..629054db9 100644
--- a/packages/notifications/slack/src/index.test.ts
+++ b/packages/notifications/slack/src/index.test.ts
@@ -177,14 +177,16 @@ describe("Slack Notifications", () => {
);
// Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- cronTimestamp: Date.now(),
- });
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
diff --git a/packages/notifications/slack/src/index.ts b/packages/notifications/slack/src/index.ts
index f61518a9c..5e905ba64 100644
--- a/packages/notifications/slack/src/index.ts
+++ b/packages/notifications/slack/src/index.ts
@@ -4,14 +4,12 @@ import type { Region } from "@openstatus/db/src/schema/constants";
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const postToWebhook = async (body: any, webhookUrl: string) => {
- try {
- await fetch(webhookUrl, {
- method: "POST",
- body: JSON.stringify(body),
- });
- } catch (e) {
- console.log(e);
- throw e;
+ const res = await fetch(webhookUrl, {
+ method: "POST",
+ body: JSON.stringify(body),
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send Slack notification: ${res.statusText}`);
}
};
@@ -37,42 +35,37 @@ export const sendAlert = async ({
const { slack: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
- try {
- await postToWebhook(
- {
- blocks: [
- {
- type: "divider",
- },
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: `
+ await postToWebhook(
+ {
+ blocks: [
+ {
+ type: "divider",
+ },
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ text: `
*🚨 Alert <${monitor.url}|${name}>*\n\n
Status Code: ${statusCode || "_empty_"}\n
Message: ${message || "_empty_"}\n
Cron Timestamp: ${cronTimestamp} (${new Date(cronTimestamp).toISOString()})
`,
- },
},
- {
- type: "context",
- elements: [
- {
- type: "mrkdwn",
- text: "Check your <https://www.openstatus.dev/app|Dashboard>.",
- },
- ],
- },
- ],
- },
- webhookUrl,
- );
- } catch (err) {
- console.log(err);
- // Do something
- }
+ },
+ {
+ type: "context",
+ elements: [
+ {
+ type: "mrkdwn",
+ text: "Check your <https://www.openstatus.dev/app|Dashboard>.",
+ },
+ ],
+ },
+ ],
+ },
+ webhookUrl,
+ );
};
export const sendRecovery = async ({
@@ -98,37 +91,32 @@ export const sendRecovery = async ({
const { slack: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
- try {
- await postToWebhook(
- {
- blocks: [
- {
- type: "divider",
+ await postToWebhook(
+ {
+ blocks: [
+ {
+ type: "divider",
+ },
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ text: `*✅ Recovered <${monitor.url}/|${name}>*`,
},
- {
- type: "section",
- text: {
+ },
+ {
+ type: "context",
+ elements: [
+ {
type: "mrkdwn",
- text: `*✅ Recovered <${monitor.url}/|${name}>*`,
+ text: "Check your <https://www.openstatus.dev/app|Dashboard>.",
},
- },
- {
- type: "context",
- elements: [
- {
- type: "mrkdwn",
- text: "Check your <https://www.openstatus.dev/app|Dashboard>.",
- },
- ],
- },
- ],
- },
- webhookUrl,
- );
- } catch (err) {
- console.log(err);
- // Do something
- }
+ ],
+ },
+ ],
+ },
+ webhookUrl,
+ );
};
export const sendDegraded = async ({
@@ -151,37 +139,32 @@ export const sendDegraded = async ({
const { slack: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
- try {
- await postToWebhook(
- {
- blocks: [
- {
- type: "divider",
+ await postToWebhook(
+ {
+ blocks: [
+ {
+ type: "divider",
+ },
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ text: `*⚠️ Degraded <${monitor.url}/|${name}>*`,
},
- {
- type: "section",
- text: {
+ },
+ {
+ type: "context",
+ elements: [
+ {
type: "mrkdwn",
- text: `*⚠️ Degraded <${monitor.url}/|${name}>*`,
+ text: "Check your <https://www.openstatus.dev/app|Dashboard>.",
},
- },
- {
- type: "context",
- elements: [
- {
- type: "mrkdwn",
- text: "Check your <https://www.openstatus.dev/app|Dashboard>.",
- },
- ],
- },
- ],
- },
- webhookUrl,
- );
- } catch (err) {
- console.log(err);
- // Do something
- }
+ ],
+ },
+ ],
+ },
+ webhookUrl,
+ );
};
export const sendTestSlackMessage = async (webhookUrl: string) => {
diff --git a/packages/notifications/telegram/src/index.test.ts b/packages/notifications/telegram/src/index.test.ts
index 86fd2bb9f..8276b015a 100644
--- a/packages/notifications/telegram/src/index.test.ts
+++ b/packages/notifications/telegram/src/index.test.ts
@@ -9,6 +9,7 @@ describe("Telegram Notifications", () => {
beforeEach(() => {
process.env.TELEGRAM_BOT_TOKEN = "test-bot-token-123";
+ // @ts-expect-error
fetchMock = spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve(new Response(null, { status: 200 })),
);
@@ -172,15 +173,16 @@ describe("Telegram Notifications", () => {
createMockNotification(),
);
- // Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- cronTimestamp: Date.now(),
- });
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
@@ -193,15 +195,16 @@ describe("Telegram Notifications", () => {
createMockNotification(),
);
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- cronTimestamp: Date.now(),
- });
-
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
// Should not call fetch when token is missing
expect(fetchMock).not.toHaveBeenCalled();
});
diff --git a/packages/notifications/telegram/src/index.ts b/packages/notifications/telegram/src/index.ts
index bfb1e0422..01e07a084 100644
--- a/packages/notifications/telegram/src/index.ts
+++ b/packages/notifications/telegram/src/index.ts
@@ -29,15 +29,10 @@ export const sendAlert = async ({
statusCode ? `status code ${statusCode}` : `error: ${message}`
}`;
- try {
- await sendMessage({
- chatId: notificationData.telegram.chatId,
- message: body,
- });
- } catch (err) {
- console.log(err);
- // Do something
- }
+ await sendMessage({
+ chatId: notificationData.telegram.chatId,
+ message: body,
+ });
};
export const sendRecovery = async ({
@@ -65,15 +60,10 @@ export const sendRecovery = async ({
const { name } = monitor;
const body = `Your monitor ${name} / ${monitor.url} is up again`;
- try {
- await sendMessage({
- chatId: notificationData.telegram.chatId,
- message: body,
- });
- } catch (err) {
- console.log(err);
- // Do something
- }
+ await sendMessage({
+ chatId: notificationData.telegram.chatId,
+ message: body,
+ });
};
export const sendDegraded = async ({
@@ -100,15 +90,10 @@ export const sendDegraded = async ({
const body = `Your monitor ${name} / ${monitor.url} is degraded `;
- try {
- await sendMessage({
- chatId: notificationData.telegram.chatId,
- message: body,
- });
- } catch (err) {
- console.log(err);
- // Do something
- }
+ await sendMessage({
+ chatId: notificationData.telegram.chatId,
+ message: body,
+ });
};
export const sendTest = async ({ chatId }: { chatId: string }) => {
@@ -134,7 +119,11 @@ export async function sendMessage({
if (!process.env.TELEGRAM_BOT_TOKEN) {
throw new Error("TELEGRAM_BOT_TOKEN is not set");
}
- return fetch(
+ const res = await fetch(
`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage?chat_id=${chatId}&text=${message}`,
);
+ if (!res.ok) {
+ throw new Error(`Failed to send telegram message: ${res.statusText}`);
+ }
+ return res;
}
diff --git a/packages/notifications/telegram/tsconfig.json b/packages/notifications/telegram/tsconfig.json
index a8a8c9309..b4382e67e 100644
--- a/packages/notifications/telegram/tsconfig.json
+++ b/packages/notifications/telegram/tsconfig.json
@@ -1,4 +1,7 @@
{
"extends": "@openstatus/tsconfig/nextjs.json",
- "include": ["src", "*.ts"]
+ "include": ["src", "*.ts"],
+ "compilerOptions": {
+ "types": ["bun-types"]
+ }
}
diff --git a/packages/notifications/twillio-sms/src/index.test.ts b/packages/notifications/twillio-sms/src/index.test.ts
index 74db91b51..f09406a24 100644
--- a/packages/notifications/twillio-sms/src/index.test.ts
+++ b/packages/notifications/twillio-sms/src/index.test.ts
@@ -13,6 +13,7 @@ describe("Twilio SMS Notifications", () => {
beforeEach(() => {
process.env.TWILLIO_ACCOUNT_ID = "test-account-id";
process.env.TWILLIO_AUTH_TOKEN = "test-auth-token";
+ // @ts-expect-error
fetchMock = spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve(new Response(null, { status: 200 })),
);
@@ -162,15 +163,16 @@ describe("Twilio SMS Notifications", () => {
createMockNotification(),
);
- // Should not throw - function catches errors internally
- await sendAlert({
- // @ts-expect-error
- monitor,
- notification,
- statusCode: 500,
- message: "Error",
- cronTimestamp: Date.now(),
- });
+ expect(
+ sendAlert({
+ // @ts-expect-error
+ monitor,
+ notification,
+ statusCode: 500,
+ message: "Error",
+ cronTimestamp: Date.now(),
+ }),
+ ).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
diff --git a/packages/notifications/twillio-sms/src/index.ts b/packages/notifications/twillio-sms/src/index.ts
index a18332cdf..9942d7a1f 100644
--- a/packages/notifications/twillio-sms/src/index.ts
+++ b/packages/notifications/twillio-sms/src/index.ts
@@ -34,22 +34,20 @@ export const sendAlert = async ({
}`,
);
- try {
- await fetch(
- `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
- {
- method: "post",
- body,
- headers: {
- Authorization: `Basic ${btoa(
- `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
- )}`,
- },
+ const res = await fetch(
+ `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
+ {
+ method: "post",
+ body,
+ headers: {
+ Authorization: `Basic ${btoa(
+ `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
+ )}`,
},
- );
- } catch (err) {
- console.log(err);
- // Do something
+ },
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
@@ -80,22 +78,20 @@ export const sendRecovery = async ({
body.set("From", "+14807252613");
body.set("Body", `Your monitor ${name} / ${monitor.url} is up again`);
- try {
- await fetch(
- `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
- {
- method: "post",
- body,
- headers: {
- Authorization: `Basic ${btoa(
- `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
- )}`,
- },
+ const res = await fetch(
+ `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
+ {
+ method: "post",
+ body,
+ headers: {
+ Authorization: `Basic ${btoa(
+ `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
+ )}`,
},
- );
- } catch (err) {
- console.log(err);
- // Do something
+ },
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
@@ -124,21 +120,19 @@ export const sendDegraded = async ({
body.set("From", "+14807252613");
body.set("Body", `Your monitor ${name} / ${monitor.url} is degraded `);
- try {
- await fetch(
- `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
- {
- method: "post",
- body,
- headers: {
- Authorization: `Basic ${btoa(
- `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
- )}`,
- },
+ const res = await fetch(
+ `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
+ {
+ method: "post",
+ body,
+ headers: {
+ Authorization: `Basic ${btoa(
+ `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
+ )}`,
},
- );
- } catch (err) {
- console.log(err);
- // Do something
+ },
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
diff --git a/packages/notifications/twillio-whatsapp/src/index.ts b/packages/notifications/twillio-whatsapp/src/index.ts
index 89ae4071b..044262c10 100644
--- a/packages/notifications/twillio-whatsapp/src/index.ts
+++ b/packages/notifications/twillio-whatsapp/src/index.ts
@@ -31,22 +31,20 @@ export const sendAlert = async ({
body.set("ContentSid", "HX8282106bfaecb7939e69f9c5564babe5");
body.set("ContentVariables", contentVariables);
- try {
- await fetch(
- `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
- {
- method: "post",
- body,
- headers: {
- Authorization: `Basic ${btoa(
- `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
- )}`,
- },
+ const res = await fetch(
+ `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
+ {
+ method: "post",
+ body,
+ headers: {
+ Authorization: `Basic ${btoa(
+ `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
+ )}`,
},
- );
- } catch (err) {
- console.log(err);
- // Do something
+ },
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to send WhatsApp message: ${res.statusText}`);
}
};
@@ -80,22 +78,20 @@ export const sendRecovery = async ({
body.set("ContentSid", "HX8fdeb4201bed18ac8838b3c0135bbf28");
body.set("ContentVariables", contentVariables);
- try {
- await fetch(
- `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
- {
- method: "post",
- body,
- headers: {
- Authorization: `Basic ${btoa(
- `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
- )}`,
- },
+ const res = await fetch(
+ `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
+ {
+ method: "post",
+ body,
+ headers: {
+ Authorization: `Basic ${btoa(
+ `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
+ )}`,
},
- );
- } catch (err) {
- console.log(err);
- // Do something
+ },
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
@@ -127,22 +123,20 @@ export const sendDegraded = async ({
body.set("ContentSid", "HX35589f2e7ac8b8be63f4bd62a60e435f");
body.set("ContentVariables", contentVariables);
- try {
- await fetch(
- `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
- {
- method: "post",
- body,
- headers: {
- Authorization: `Basic ${btoa(
- `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
- )}`,
- },
+ const res = await fetch(
+ `https://api.twilio.com/2010-04-01/Accounts/${env.TWILLIO_ACCOUNT_ID}/Messages.json`,
+ {
+ method: "post",
+ body,
+ headers: {
+ Authorization: `Basic ${btoa(
+ `${env.TWILLIO_ACCOUNT_ID}:${env.TWILLIO_AUTH_TOKEN}`,
+ )}`,
},
- );
- } catch (err) {
- console.log(err);
- // Do something
+ },
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
diff --git a/packages/notifications/webhook/src/index.ts b/packages/notifications/webhook/src/index.ts
index 7a51c23a7..7a04bbcd2 100644
--- a/packages/notifications/webhook/src/index.ts
+++ b/packages/notifications/webhook/src/index.ts
@@ -34,19 +34,17 @@ export const sendAlert = async ({
errorMessage: message,
});
- try {
- await fetch(notificationData.webhook.endpoint, {
- method: "post",
- body: JSON.stringify(body),
- headers: notificationData.webhook.headers
- ? transformHeaders(notificationData.webhook.headers)
- : {
- "Content-Type": "application/json",
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+ const res = await fetch(notificationData.webhook.endpoint, {
+ method: "post",
+ body: JSON.stringify(body),
+ headers: notificationData.webhook.headers
+ ? transformHeaders(notificationData.webhook.headers)
+ : {
+ "Content-Type": "application/json",
+ },
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send webhook notification: ${res.statusText}`);
}
};
@@ -80,19 +78,17 @@ export const sendRecovery = async ({
errorMessage: message,
});
const url = notificationData.webhook.endpoint;
- try {
- await fetch(url, {
- method: "post",
- body: JSON.stringify(body),
- headers: notificationData.webhook.headers
- ? transformHeaders(notificationData.webhook.headers)
- : {
- "Content-Type": "application/json",
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+ const res = await fetch(url, {
+ method: "post",
+ body: JSON.stringify(body),
+ headers: notificationData.webhook.headers
+ ? transformHeaders(notificationData.webhook.headers)
+ : {
+ "Content-Type": "application/json",
+ },
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
@@ -124,19 +120,17 @@ export const sendDegraded = async ({
errorMessage: message,
});
- try {
- await fetch(notificationData.webhook.endpoint, {
- method: "post",
- body: JSON.stringify(body),
- headers: notificationData.webhook.headers
- ? transformHeaders(notificationData.webhook.headers)
- : {
- "Content-Type": "application/json",
- },
- });
- } catch (err) {
- console.log(err);
- // Do something
+ const res = await fetch(notificationData.webhook.endpoint, {
+ method: "post",
+ body: JSON.stringify(body),
+ headers: notificationData.webhook.headers
+ ? transformHeaders(notificationData.webhook.headers)
+ : {
+ "Content-Type": "application/json",
+ },
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to send SMS: ${res.statusText}`);
}
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fe4432b30..ae1a006ed 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1118,6 +1118,9 @@ importers:
drizzle-orm:
specifier: 0.44.4
version: 0.44.4(@libsql/[email protected])(@opentelemetry/[email protected])(@types/[email protected])([email protected])
+ effect:
+ specifier: 3.19.12
+ version: 3.19.12
hono:
specifier: 4.5.3
version: 4.5.3
@@ -6286,6 +6289,9 @@ packages:
'@socket.io/[email protected]':
resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==}
+ '@standard-schema/[email protected]':
+ resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
+
'@standard-schema/[email protected]':
resolution: {integrity: sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==}
@@ -7947,6 +7953,9 @@ packages:
resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==}
+ resolution: {integrity: sha512-7F9RGTrCTC3D7nh9Zw+3VlJWwZgo5k33KA+476BAaD0rKIXKZsY/jQ+ipyhR/Avo239Fi6GqAVFs1mqM1IJ7yg==}
+
resolution: {integrity: sha512-ov8rBoOBhVawpzdre+Cmz4FB+y66Eqrk6Gwqd8NGxuhv99GQ8XqMAr351KEkOt7gukXWDg6gJWEMKgL2RLMPtA==}
@@ -8170,6 +8179,10 @@ packages:
resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==}
engines: {node: '>=4'}
+ resolution: {integrity: sha512-h5+1OzzfCC3Ef7VbtKdcv7zsstUQwUDlYpUTvjeUsJAssPgLn7QzbboPtL5ro04Mq0rPOsMzl7q5hIbRs2wD1A==}
+ engines: {node: '>=8.0.0'}
+
resolution: {integrity: sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==}
@@ -10147,6 +10160,9 @@ packages:
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
engines: {node: '>=6'}
+ resolution: {integrity: sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==}
+
resolution: {integrity: sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==}
engines: {node: '>=0.6'}
@@ -16210,7 +16226,7 @@ snapshots:
json5: 2.2.3
log-symbols: 4.1.0
module-punycode: [email protected]
node-html-parser: 7.0.1
ora: 5.4.1
pretty-bytes: 6.1.1
@@ -17009,6 +17025,8 @@ snapshots:
'@socket.io/[email protected]': {}
+ '@standard-schema/[email protected]': {}
+
'@standard-schema/[email protected]': {}
'@stripe/[email protected]': {}
@@ -18738,6 +18756,11 @@ snapshots:
+ dependencies:
+ '@standard-schema/spec': 1.1.0
+ fast-check: 3.23.2
+
@@ -19084,6 +19107,10 @@ snapshots:
iconv-lite: 0.4.24
tmp: 0.0.33
+ dependencies:
+ pure-rand: 6.1.0
+
@@ -20936,7 +20963,7 @@ snapshots:
react: 19.2.2
react-dom: 19.2.2([email protected])
dependencies:
'@next/env': 15.5.2
'@swc/helpers': 0.5.15
@@ -21565,6 +21592,8 @@ snapshots:
+
dependencies:
side-channel: 1.1.0