fix: treat empty IMGW warning products as no warnings

This commit is contained in:
zv
2026-06-12 21:51:44 +02:00
parent 1ff76cf847
commit 3309e03acb
5 changed files with 31 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import { NextResponse } from "next/server";
import { isImgwNoProductsResponse, readImgwResponseBody } from "@/lib/imgw-empty-response";
const ALLOWED_PATHS = new Set([
"synop",
@@ -28,6 +29,12 @@ export async function GET(_: Request, context: { params: Promise<{ path: string[
headers: { Accept: "application/json", "User-Agent": USER_AGENT },
});
if (!response.ok) {
const body = await readImgwResponseBody(response);
if ((resource === "warningsmeteo" || resource === "warningshydro") && response.status === 404 && isImgwNoProductsResponse(body.json)) {
return NextResponse.json([], {
headers: { "Cache-Control": "public, s-maxage=300, stale-while-revalidate=600" },
});
}
return NextResponse.json({ error: "IMGW API jest chwilowo niedostępne." }, { status: response.status });
}
const data: unknown = await response.json();