fix(link-resolver): add retry for transient Odesli API errors

The Odesli API can fail with connection errors on rapid successive
requests (connection pool staleness). Add a single retry with 500ms
delay to handle transient network failures gracefully.

Also improve song.link URL handling to hint track vs album detection.
This commit is contained in:
vicrodh committed 2026-02-20 16:37:58 -06:00
1 parent 9ba09ff37b
commit 97e319f2d9
1 file changed
+16 -4
+16 -4
View File
@@ -1509,8 +1509,10 @@ pub async fn v2_resolve_music_link(
}
MusicResource::SongLink { url: source_url } => {
// song.link URLs: try to detect track vs album from the URL format
let is_track_hint = source_url.contains("song.link/");
resolve_via_odesli_and_search(
&state.songlink, &source_url, None, false, &bridge, &runtime,
&state.songlink, &source_url, None, is_track_hint, &bridge, &runtime,
).await
}
}
@@ -1531,11 +1533,21 @@ async fn resolve_via_odesli_and_search(
) -> Result<MusicLinkResult, RuntimeError> {
let provider_name = provider.map(|p| format!("{:?}", p));
// 1. Call Odesli API to identify the content
let response = songlink
// 1. Call Odesli API to identify the content (with one retry for transient errors)
let response = match songlink
.get_by_url(url, crate::share::ContentType::Track)
.await
.map_err(|e| RuntimeError::Internal(format!("Odesli API error: {}", e)))?;
{
Ok(r) => r,
Err(first_err) => {
log::warn!("Link resolver: Odesli first attempt failed: {}, retrying...", first_err);
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
songlink
.get_by_url(url, crate::share::ContentType::Track)
.await
.map_err(|e| RuntimeError::Internal(format!("Odesli API error: {}", e)))?
}
};
let title = response.title.as_deref().unwrap_or("").trim();
let artist = response.artist.as_deref().unwrap_or("").trim();