feat: Implement initial PolyWeather dashboard with city list, detail view, map, and API endpoints.
This commit is contained in:
+15
-2
@@ -1,9 +1,20 @@
|
||||
import type { CityDetail, CitySummary } from "@/lib/types";
|
||||
|
||||
async function readError(res: Response, fallback: string) {
|
||||
try {
|
||||
const data = await res.json();
|
||||
const msg = data?.error ? String(data.error) : fallback;
|
||||
const detail = data?.detail ? ` ${String(data.detail)}` : "";
|
||||
return `${msg}${detail}`.trim();
|
||||
} catch {
|
||||
return `${fallback}: ${res.status}`;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCities(): Promise<CitySummary[]> {
|
||||
const res = await fetch("/api/cities", { cache: "no-store" });
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to load cities: ${res.status}`);
|
||||
throw new Error(await readError(res, `Failed to load cities (${res.status})`));
|
||||
}
|
||||
const data = await res.json();
|
||||
return data.cities ?? [];
|
||||
@@ -21,7 +32,9 @@ export async function getCityDetail(
|
||||
},
|
||||
);
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to load city detail: ${res.status}`);
|
||||
throw new Error(
|
||||
await readError(res, `Failed to load city detail (${res.status})`),
|
||||
);
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user