Additional structs & enums for API error responses
Obviously the Gitea API can return errors, which are also JSON strings. Theres a new error response struct to collect these, and an enum for Serde to unpack which ever variant happens to come back.
This commit is contained in:
24
src/lib.rs
24
src/lib.rs
@@ -7,7 +7,7 @@ pub fn module_echo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A struct matching a Gitea "Release" entry
|
/// A struct matching a Gitea "Release" entry
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
pub struct ReleaseInfo {
|
pub struct ReleaseInfo {
|
||||||
id: usize,
|
id: usize,
|
||||||
tag_name: String,
|
tag_name: String,
|
||||||
@@ -26,7 +26,7 @@ pub struct ReleaseInfo {
|
|||||||
author: Author,
|
author: Author,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
pub struct Author {
|
pub struct Author {
|
||||||
id: usize,
|
id: usize,
|
||||||
login: String,
|
login: String,
|
||||||
@@ -50,11 +50,25 @@ impl CreateReleaseOption {
|
|||||||
pub fn new(name: String) -> Self {
|
pub fn new(name: String) -> Self {
|
||||||
Self{
|
Self{
|
||||||
body: String::from("hard-coded test body"),
|
body: String::from("hard-coded test body"),
|
||||||
draft: true,
|
draft: false,
|
||||||
name,
|
name,
|
||||||
prerelease: true,
|
prerelease: true,
|
||||||
tag_name: String::from("hard-coded-test"),
|
tag_name: String::from("big-goof"),
|
||||||
target_commitish: String::from("3171c892480c46976106fa465d04fdb7e734dd53")
|
target_commitish: String::from("548ceecc7528901a7b4376091b42e410d950affc")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct ApiError {
|
||||||
|
message: String,
|
||||||
|
url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum CreateResult {
|
||||||
|
Success(ReleaseInfo),
|
||||||
|
ErrWithMessage(ApiError),
|
||||||
|
Empty
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user