diff --git a/apps/web/src/components/events-display/index.tsx b/apps/web/src/components/events-display/index.tsx
index 305c5aa3..e153a40b 100644
--- a/apps/web/src/components/events-display/index.tsx
+++ b/apps/web/src/components/events-display/index.tsx
@@ -76,9 +76,14 @@ async function EventList({
}) {
const events = await fetchEvents();
+ if (!events.ok) {
+ console.warn("Failed to fetch events from Ilmomasiina", events.error);
+ return null;
+ }
+
return (
- {events.map((event) => (
+ {events.data.map((event) => (
{
+ ok: true;
+ error: null;
+ data: T;
+}
+
+export interface ErrorResponse {
+ ok: false;
+ error: ErrorType;
+ data: null;
+}
+
+export type ApiResponse = OkResponse | ErrorResponse;
+
+export const ok = (data: T): OkResponse => ({
+ ok: true,
+ error: null,
+ data,
+});
+
+export const err = (error: ErrorType): ErrorResponse => ({
+ ok: false,
+ error,
+ data: null,
+});
diff --git a/apps/web/src/lib/api/external/ilmomasiina.ts b/apps/web/src/lib/api/external/ilmomasiina.ts
index 7dc60e55..8dd8216c 100644
--- a/apps/web/src/lib/api/external/ilmomasiina.ts
+++ b/apps/web/src/lib/api/external/ilmomasiina.ts
@@ -1,3 +1,6 @@
+import type { ApiResponse } from "./helpers";
+import { err, ok } from "./helpers";
+
export type IlmomasiinaResponse = IlmomasiinaEvent[];
export interface IlmomasiinaEvent {
@@ -39,9 +42,14 @@ export interface EventQuota {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- ideally would throw during build, but let's at least throw here if it's missing
const baseUrl = process.env.PUBLIC_ILMOMASIINA_URL!;
-export const fetchEvents = async (): Promise => {
+export const fetchEvents = async (): Promise<
+ ApiResponse
+> => {
const response = await fetch(`${baseUrl}/api/events`);
+ if (!response.ok) {
+ return err("ilmomasiina-fetch-fail");
+ }
const data = (await response.json()) as IlmomasiinaResponse;
- return data;
+ return ok(data);
};