added fix for json with a count of 0
This commit is contained in:
parent
063ce06aaa
commit
0786c26260
11
src/tags.rs
11
src/tags.rs
@ -20,6 +20,7 @@ pub struct Images {
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Tags {
|
pub struct Tags {
|
||||||
|
count: usize,
|
||||||
#[serde(rename(deserialize = "next"))]
|
#[serde(rename(deserialize = "next"))]
|
||||||
next_page: Option<String>,
|
next_page: Option<String>,
|
||||||
#[serde(rename(deserialize = "previous"))]
|
#[serde(rename(deserialize = "previous"))]
|
||||||
@ -29,9 +30,14 @@ pub struct Tags {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
/// repo string contains an illegal character
|
||||||
InvalidCharacter(char),
|
InvalidCharacter(char),
|
||||||
|
/// couldn't fetch json with reqwest
|
||||||
Fetching(String),
|
Fetching(String),
|
||||||
|
/// a serde error
|
||||||
Converting(String),
|
Converting(String),
|
||||||
|
/// invalid repos show a valid json with 0 tags
|
||||||
|
NoTagsFound,
|
||||||
NoPrevPage,
|
NoPrevPage,
|
||||||
NoNextPage,
|
NoNextPage,
|
||||||
}
|
}
|
||||||
@ -44,6 +50,7 @@ impl fmt::Display for Error {
|
|||||||
Error::Converting(s) => write!(f, "Converting error: {}", s),
|
Error::Converting(s) => write!(f, "Converting error: {}", s),
|
||||||
Error::NoNextPage => write!(f, "No next page available"),
|
Error::NoNextPage => write!(f, "No next page available"),
|
||||||
Error::NoPrevPage => write!(f, "No previous page available"),
|
Error::NoPrevPage => write!(f, "No previous page available"),
|
||||||
|
Error::NoTagsFound => write!(f, "Given Repo has 0 tags. Is it valid?"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,6 +76,10 @@ impl Tags {
|
|||||||
Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))),
|
Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if tags.count == 0 {
|
||||||
|
return Err(Error::NoTagsFound);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(tags)
|
Ok(tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user