diff --git a/src/docker_hub.rs b/src/docker_hub.rs index 61ebcbe..b0e1085 100644 --- a/src/docker_hub.rs +++ b/src/docker_hub.rs @@ -1,3 +1,4 @@ +use std::io::Write; use serde::{Deserialize, Serialize}; use crate::{DockerTagsFetcher, QueryArgs}; @@ -61,12 +62,18 @@ impl DockerTagsFetcher for DockerHubTagsFetcher { let mut url = format!("https://hub.docker.com/v2/namespaces/{namespace}/repositories/{repository}/tags?page={page}&page_size={page_size}"); let mut results: Vec = Vec::new(); loop { - let text = reqwest::blocking::get(url).unwrap().text().unwrap(); - let mut response: DockerResponse = serde_json::from_str(&text).unwrap(); - results.append(&mut response.results); - url = match response.next { - None => { break; } - Some(next) => { next } + let resp = reqwest::blocking::get(&url).unwrap(); + if resp.status().is_success() { + let text = resp.text().unwrap(); + let mut response: DockerResponse = serde_json::from_str(&text).unwrap(); + results.append(&mut response.results); + url = match response.next { + None => { break; } + Some(next) => { next } + }; + } else { + let _x = writeln!(std::io::stdout(), "Image not found: {}/{}", namespace, repository); + break; }; } let mut filtered = results.into_iter() diff --git a/src/registry.rs b/src/registry.rs index 68c0d30..2dea259 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -39,7 +39,10 @@ impl DockerTagsFetcher for RegistryTagsFetcher { let mut results = Vec::::new(); if let Ok(r) = response { let json: RegistryTagsResponse = serde_json::from_str(r.text().unwrap().as_str()).unwrap(); - results.append(&mut json.tags.unwrap()); + match json.tags { + Some(mut x) => { results.append(&mut x); } + None => { results.push(format!("Image not found: {}/{}", namespace, repository)); } + } }; results }