diff --git a/src/app.rs b/src/app.rs index 6b27e0f..7b5b377 100644 --- a/src/app.rs +++ b/src/app.rs @@ -35,15 +35,22 @@ async fn patrons() -> Result> { let creds: Credentials = envy::prefixed("PATREON_").from_env().unwrap(); let cli = Client::new(creds); - if let Ok(camp) = cli.campaign().await { - let id = camp.data[0].id.clone(); - if let Ok(users) = cli.pledges(id).await { - Ok(Some(users)) - } else { + match cli.campaign().await { + Ok(camp) => { + let id = camp.data[0].id.clone(); + + match cli.pledges(id).await { + Ok(users) => Ok(Some(users)), + Err(why) => { + log::error!("error getting pledges: {:?}", why); + Ok(None) + } + } + } + Err(why) => { + log::error!("error getting patreon campaign: {:?}", why); Ok(None) } - } else { - Ok(None) } } diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 6f785ff..5c51352 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -3,7 +3,7 @@ use crate::{ templates::{self, Html, RenderRucte}, }; use lazy_static::lazy_static; -use prometheus::{IntCounterVec, register_int_counter_vec, opts}; +use prometheus::{opts, register_int_counter_vec, IntCounterVec}; use std::{convert::Infallible, fmt, sync::Arc}; use warp::{ http::{Response, StatusCode}, @@ -41,8 +41,13 @@ pub async fn patrons(state: Arc) -> Result { HIT_COUNTER.with_label_values(&["patrons"]).inc(); let state = state.clone(); match &state.patrons { - None => Response::builder().html(|o| templates::error_html(o, "Could not load patrons, let me know the API token expired again".to_string())), - Some(patrons) => Response::builder().html(|o| templates::patrons_html(o, patrons.clone())) + None => Response::builder().status(500).html(|o| { + templates::error_html( + o, + "Could not load patrons, let me know the API token expired again".to_string(), + ) + }), + Some(patrons) => Response::builder().html(|o| templates::patrons_html(o, patrons.clone())), } } @@ -97,9 +102,11 @@ impl From for warp::reject::Rejection { } lazy_static! { - static ref REJECTION_COUNTER: IntCounterVec = - register_int_counter_vec!(opts!("rejections", "Number of rejections by kind"), &["kind"]) - .unwrap(); + static ref REJECTION_COUNTER: IntCounterVec = register_int_counter_vec!( + opts!("rejections", "Number of rejections by kind"), + &["kind"] + ) + .unwrap(); } pub async fn rejection(err: Rejection) -> Result { @@ -111,7 +118,9 @@ pub async fn rejection(err: Rejection) -> Result { path = "".into(); code = StatusCode::NOT_FOUND; } else if let Some(SeriesNotFound(series)) = err.find() { - REJECTION_COUNTER.with_label_values(&["SeriesNotFound"]).inc(); + REJECTION_COUNTER + .with_label_values(&["SeriesNotFound"]) + .inc(); log::error!("invalid series {}", series); path = format!("/blog/series/{}", series); code = StatusCode::NOT_FOUND;