blob: 8ae6e788a3d18da98eb865785d4c74baee89cd40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import {
StopArrivalsResponseSchema,
type StopArrivalsResponse,
} from "./schema";
export const fetchArrivals = async (
stopId: string,
reduced: boolean = false
): Promise<StopArrivalsResponse> => {
const resp = await fetch(
`/api/stops/arrivals?id=${stopId}&reduced=${reduced}`,
{
headers: {
Accept: "application/json",
},
}
);
if (!resp.ok) {
throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
}
const data = await resp.json();
try {
return StopArrivalsResponseSchema.parse(data);
} catch (e) {
console.error("Zod parsing failed for arrivals:", e);
console.log("Received data:", data);
throw e;
}
};
|