Skip to content

Open-source status page, incident response and uptime monitoring

🔌 solved error codes (#632)

Kushagra Sharma324339d24b6d
diff --git a/apps/server/src/v1/incidents.test.ts b/apps/server/src/v1/incidents.test.ts
index ec14d5b3c..f8e518769 100644
--- a/apps/server/src/v1/incidents.test.ts
+++ b/apps/server/src/v1/incidents.test.ts
@@ -56,7 +56,7 @@ test("Update an incident not in db should return 404", async () => {
acknowledgedAt: "2023-11-08T21:03:13.000Z",
}),
});
- expect(res.status).toBe(200);
+ expect(res.status).toBe(404);
expect(await res.json()).toMatchObject({
code: 404,
message: "Not Found",
diff --git a/apps/server/src/v1/incidents.ts b/apps/server/src/v1/incidents.ts
index 815f74360..65e7a3df7 100644
--- a/apps/server/src/v1/incidents.ts
+++ b/apps/server/src/v1/incidents.ts
@@ -102,7 +102,7 @@ incidentsApi.openapi(getAllRoute, async (c) => {
.where(eq(incidentTable.workspaceId, workspaceId))
.all();
- if (!result) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!result) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const data = z.array(IncidentSchema).parse(result);
return c.jsonT(data);
@@ -152,7 +152,7 @@ incidentsApi.openapi(getRoute, async (c) => {
)
.get();
- if (!result) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!result) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const data = IncidentSchema.parse(result);
return c.jsonT(data);
@@ -204,7 +204,7 @@ incidentsApi.openapi(putRoute, async (c) => {
const input = c.req.valid("json");
const workspaceId = Number(c.get("workspaceId"));
const { id } = c.req.valid("param");
- if (!id) return c.jsonT({ code: 400, message: "Bad Request" });
+ if (!id) return c.jsonT({ code: 400, message: "Bad Request" }, 400);
const _incident = await db
.select()
@@ -217,10 +217,10 @@ incidentsApi.openapi(putRoute, async (c) => {
)
.get();
- if (!_incident) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_incident) return c.jsonT({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _incident.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" });
+ return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
const _newIncident = await db
.update(incidentTable)
diff --git a/apps/server/src/v1/monitor.test.ts b/apps/server/src/v1/monitor.test.ts
index 0a58b5dc9..89246a62f 100644
--- a/apps/server/src/v1/monitor.test.ts
+++ b/apps/server/src/v1/monitor.test.ts
@@ -193,7 +193,7 @@ test("Update a monitor not in db should return 404", async () => {
},
body: JSON.stringify(data),
});
- expect(res.status).toBe(200);
+ expect(res.status).toBe(404);
expect(await res.json()).toMatchObject({
code: 404,
diff --git a/apps/server/src/v1/monitor.ts b/apps/server/src/v1/monitor.ts
index a36db2e33..680d6d4aa 100644
--- a/apps/server/src/v1/monitor.ts
+++ b/apps/server/src/v1/monitor.ts
@@ -208,7 +208,7 @@ monitorApi.openapi(getAllRoute, async (c) => {
.where(eq(monitor.workspaceId, workspaceId))
.all();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const data = z.array(MonitorSchema).parse(_monitor);
@@ -262,10 +262,10 @@ monitorApi.openapi(getRoute, async (c) => {
.where(eq(monitor.id, monitorId))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" });
+ return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
const data = MonitorSchema.parse(_monitor);
@@ -391,10 +391,10 @@ monitorApi.openapi(putRoute, async (c) => {
const workspacePlan = c.get("workspacePlan");
const { id } = c.req.valid("param");
- if (!id) return c.jsonT({ code: 400, message: "Bad Request" });
+ if (!id) return c.jsonT({ code: 400, message: "Bad Request" }, 400);
if (!workspacePlan.limits.periodicity.includes(input.periodicity))
- return c.jsonT({ code: 403, message: "Forbidden" });
+ return c.jsonT({ code: 403, message: "Forbidden" }, 403);
const _monitor = await db
.select()
@@ -402,10 +402,10 @@ monitorApi.openapi(putRoute, async (c) => {
.where(eq(monitor.id, Number(id)))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" });
+ return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
const { headers, ...rest } = input;
const _newMonitor = await db
@@ -465,10 +465,10 @@ monitorApi.openapi(deleteRoute, async (c) => {
.where(eq(monitor.id, monitorId))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" });
+ return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
await db.delete(monitor).where(eq(monitor.id, monitorId)).run();
return c.jsonT({ message: "Deleted" });
@@ -538,10 +538,10 @@ monitorApi.openapi(getMonitorStats, async (c) => {
.where(eq(monitor.id, monitorId))
.get();
- if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_monitor) return c.jsonT({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _monitor.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" });
+ return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
const cache = await redis.get<z.infer<typeof dailyStatsSchemaArray>>(
`${monitorId}-daily-stats`,
diff --git a/apps/server/src/v1/page.ts b/apps/server/src/v1/page.ts
index 486c9f4b9..799c19057 100644
--- a/apps/server/src/v1/page.ts
+++ b/apps/server/src/v1/page.ts
@@ -84,7 +84,7 @@ pageApi.openapi(postRouteSubscriber, async (c) => {
.where(and(eq(page.id, pageId), eq(page.workspaceId, workspaceId)))
.get();
- if (!_page) return c.jsonT({ code: 401, message: "Not authorized" });
+ if (!_page) return c.jsonT({ code: 401, message: "Not authorized" }, 401);
const alreadySubscribed = await db
.select()
@@ -97,7 +97,7 @@ pageApi.openapi(postRouteSubscriber, async (c) => {
)
.get();
if (alreadySubscribed)
- return c.jsonT({ code: 401, message: "Already subscribed" });
+ return c.jsonT({ code: 401, message: "Already subscribed" }, 401);
// TODO: send email for verification
const token = (Math.random() + 1).toString(36).substring(10);
diff --git a/apps/server/src/v1/statusReport.test.ts b/apps/server/src/v1/statusReport.test.ts
index dc44888d3..a20b96b0d 100644
--- a/apps/server/src/v1/statusReport.test.ts
+++ b/apps/server/src/v1/statusReport.test.ts
@@ -133,7 +133,7 @@ test("Create a status report update not in db should return 404", async () => {
message: "Test Status Report",
}),
});
- expect(res.status).toBe(200);
+ expect(res.status).toBe(404);
expect(await res.json()).toMatchObject({
code: 404,
message: "Not Found",
diff --git a/apps/server/src/v1/statusReport.ts b/apps/server/src/v1/statusReport.ts
index 4c59d76e6..22e1de026 100644
--- a/apps/server/src/v1/statusReport.ts
+++ b/apps/server/src/v1/statusReport.ts
@@ -101,7 +101,7 @@ statusReportApi.openapi(getAllRoute, async (c) => {
where: eq(statusReport.workspaceId, workspaceId),
});
- if (!_statusReports) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_statusReports) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const data = z.array(statusReportExtendedSchema).parse(
_statusReports.map((statusReport) => ({
@@ -160,7 +160,7 @@ statusReportApi.openapi(getRoute, async (c) => {
),
});
- if (!_statusUpdate) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_statusUpdate) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const data = statusReportExtendedSchema.parse({
..._statusUpdate,
status_report_updates: _statusUpdate.statusReportUpdates.map(
@@ -267,10 +267,10 @@ statusReportApi.openapi(deleteRoute, async (c) => {
.where(eq(statusReport.id, statusReportId))
.get();
- if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" }, 404);
if (workspaceId !== _statusReport.workspaceId)
- return c.jsonT({ code: 401, message: "Unauthorized" });
+ return c.jsonT({ code: 401, message: "Unauthorized" }, 401);
await db
.delete(statusReport)
@@ -332,7 +332,7 @@ statusReportApi.openapi(postRouteUpdate, async (c) => {
)
.get();
- if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!_statusReport) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const _statusReportUpdate = await db
.insert(statusReportUpdate)
diff --git a/apps/server/src/v1/statusReportUpdate.ts b/apps/server/src/v1/statusReportUpdate.ts
index ccfbdc7c3..d218030b8 100644
--- a/apps/server/src/v1/statusReportUpdate.ts
+++ b/apps/server/src/v1/statusReportUpdate.ts
@@ -96,7 +96,7 @@ statusReportUpdateApi.openapi(getUpdateRoute, async (c) => {
.where(eq(statusReportUpdate.id, Number(id)))
.get();
- if (!update) return c.jsonT({ code: 404, message: "Not Found" });
+ if (!update) return c.jsonT({ code: 404, message: "Not Found" }, 404);
const currentStatusReport = await db
.select()
@@ -109,7 +109,7 @@ statusReportUpdateApi.openapi(getUpdateRoute, async (c) => {
)
.get();
if (!currentStatusReport)
- return c.jsonT({ code: 401, message: "Not Authorized" });
+ return c.jsonT({ code: 401, message: "Not Authorized" }, 401);
const data = statusUpdateSchema.parse(update);
@@ -165,7 +165,7 @@ statusReportUpdateApi.openapi(createStatusUpdate, async (c) => {
)
.get();
if (!_currentStatusReport)
- return c.jsonT({ code: 401, message: "Not Authorized" });
+ return c.jsonT({ code: 401, message: "Not Authorized" }, 401);
const res = await db
.insert(statusReportUpdate)