fix: treat empty IMGW warning products as no warnings
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user