Say what a static feed actually answered

f7912e4 · Gabriel Morell · 2026-09-06 20:36

5 files +25 -1
Message
{commit_body(@commit)}

Files changed

modified apps/room_gtfs/lib/room_gtfs/gtfs_worker.ex
+25 −1
@@ -2283,8 +2283,9 @@ end
2283 2283 bcast(id, :downloading, 1, 11)
2284 2284
2285 2285 case HTTPoison.get(cfg.config.url, [], @static_http) do
2286 − {:ok, result} ->
2286 + {:ok, %{status_code: 200} = result} ->
2287 2287 bcast(id, :extracting, 2, 11)
2288 + Logger.info("GTFS::#{id} downloaded #{byte_size(result.body)} bytes")
2288 2289
2289 2290 case result.body |> trim_zip_tail() |> Unzip.InMem.new() |> Unzip.new() do
2290 2291 {:ok, unzip} ->
@@ -2340,12 +2341,35 @@ end
2340 2341 {:error, {:unzip, term}}
2341 2342 end
2342 2343
2344 + # A server that answers a zip URL with an error page was, until now,
2345 + # reported as a feed that was not a readable zip -- true, and useless.
2346 + # It sent an HTML apology and the answer is to look at what it said,
2347 + # which is the same call the realtime fetches have always made.
2348 + {:ok, result} ->
2349 + Logger.error(
2350 + "GTFS::#{id} static feed answered HTTP #{result.status_code} " <>
2351 + "(#{byte_size(result.body)} bytes): #{static_body_hint(result.body)}"
2352 + )
2353 +
2354 + {:error, {:status, result.status_code}}
2355 +
2343 2356 {:error, error} ->
2344 2357 Logger.error("GTFS::#{id} static feed download failed: #{inspect(error)}")
2345 2358 {:error, {:download, error}}
2346 2359 end
2347 2360 end
2348 2361
2362 + # The first line of whatever came instead, flattened. Enough to tell a rate
2363 + # limit from a login page from a 404, and short enough to sit in a log line.
2364 + defp static_body_hint(body) when is_binary(body) do
2365 + body
2366 + |> binary_part(0, min(byte_size(body), 200))
2367 + |> String.replace(~r/\s+/, " ")
2368 + |> String.trim()
2369 + end
2370 +
2371 + defp static_body_hint(_body), do: "no body"
2372 +
2349 2373 defp replace(string) do
2350 2374 String.replace(string, ~s("), "")
2351 2375 end

Parents: 51830b0