Skip to content

Commit

Permalink
fix: produce slightly better errors (#229)
Browse files Browse the repository at this point in the history
* fix: better ivr and 7tv errors

* chore: clarify refund
  • Loading branch information
Nerixyz authored Nov 7, 2024
1 parent 0f03f49 commit 5720cea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/services/ivr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ lazy_static! {
.unwrap();
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[non_exhaustive]
pub struct ModVips {
#[serde(default)]
pub vips: Vec<User>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[non_exhaustive]
pub struct User {
pub id: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[non_exhaustive]
struct IvrErrorResponse {
error: IvrError,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
#[non_exhaustive]
struct IvrError {
message: String,
Expand All @@ -51,13 +52,13 @@ where
let status = response.status();
match status {
s if s.is_success() => Ok(response.json().await?),
_ => {
let json: IvrErrorResponse = response.json().await?;
Err(anyhow!(
"IVR Error - {} (http-status={})",
json.error.message,
status
))
}
_ => match response.json::<IvrErrorResponse>().await {
Ok(json) => {
Err(anyhow!("IVR Error - {} ({status})", json.error.message))
}
Err(e) => Err(anyhow!(
"IVR error {status} + failed to decode error response"
)),
},
}
}
2 changes: 1 addition & 1 deletion src/services/rewards/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn reply_to_redemption(
log_err!(
send_chat_message(
broadcaster_id,
&format!("@{} {}", user, e),
&format!("@{} [⚠ Refund] {}", user, e),
&twitch::get_token(),
)
.await,
Expand Down
2 changes: 2 additions & 0 deletions src/services/seven_tv/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct SevenUserResponse {
#[derive(Deserialize, Debug)]
#[non_exhaustive]
pub struct SevenUser {
#[serde(default)]
pub editors: Vec<SevenEditor>,
}

Expand All @@ -86,6 +87,7 @@ pub struct SevenUser {
pub struct SevenEmoteSet {
pub id: String,
pub capacity: usize,
#[serde(default)]
pub emotes: Vec<SevenEmote>,
}

Expand Down

0 comments on commit 5720cea

Please sign in to comment.