From 1d9a53f3393a33c8542dab4a2c315599083296db Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Fri, 10 May 2024 22:02:36 +0200 Subject: [PATCH] improved the logging around retried tileserver responses --- server/main-api/src/maps/fetch_tile.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/main-api/src/maps/fetch_tile.rs b/server/main-api/src/maps/fetch_tile.rs index c5f91c545..a6fb3dce1 100644 --- a/server/main-api/src/maps/fetch_tile.rs +++ b/server/main-api/src/maps/fetch_tile.rs @@ -1,6 +1,6 @@ -use std::fmt; use std::fmt::Display; use std::time::Duration; +use std::{fmt, io}; use cached::proc_macro::io_cached; use log::{error, warn}; @@ -118,17 +118,21 @@ async fn download_map_image(location: TileLocation) -> Result, BoxedErro z = location.z ); for i in 1..5 { - let res = reqwest::get(&url).await?.bytes().await?; + let response = reqwest::get(&url).await?; + let status = response.status(); + if status.as_u16() == 400 { + error!("could not find {location:?} at {url} with {status:?}"); + return Err(io::Error::other("could not find requested tile").into()); + } + let bytes = response.bytes().await?; // wait with exponential backoff - if res.len() > 500 { - return Ok(res.into()); + let size = bytes.len(); + if size > 500 { + return Ok(bytes.into()); } let wait_time_ms = 1.5_f32.powi(i).round() as u64; let wait_time = Duration::from_millis(wait_time_ms); - warn!( - "retrying tileserver-request in {wait_time:?} because it is only {request_len}B", - request_len = res.len() - ); + warn!("retrying {url} in {wait_time:?} because response({status:?}) is only {size}B"); tokio::time::sleep(wait_time).await; } Err(format!("Got only short Responses from {url}").into())