Add better logging
This commit is contained in:
parent
6e782a72f7
commit
81890b7d7d
29
src/main.rs
29
src/main.rs
|
@ -124,7 +124,7 @@ async fn get_full_post_data(project_id: String) -> Result<CohostPostsPage, Error
|
|||
// Not cached because it's never used individually.
|
||||
async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage, ErrorResponse> {
|
||||
let posts_url = cohost_posts_api_url(&project_id, page);
|
||||
eprintln!("making request to {}", posts_url);
|
||||
eprintln!("[INT] making request to {}", posts_url);
|
||||
match CLIENT.get(posts_url).send().await {
|
||||
Ok(v) => match v.status() {
|
||||
StatusCode::OK => match v.json::<CohostPostsPage>().await {
|
||||
|
@ -134,14 +134,14 @@ async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage,
|
|||
"Couldn't deserialize Cohost posts page for '{}': {:?}",
|
||||
project_id, e
|
||||
);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
return Err(ErrorResponse::InternalError(err));
|
||||
}
|
||||
},
|
||||
// TODO NORA: Handle possible redirects
|
||||
s => {
|
||||
let err = format!("Didn't receive status code 200 for posts for Cohost project '{}'; got {:?} instead.", page, s);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
return Err(ErrorResponse::NotFound(err));
|
||||
}
|
||||
},
|
||||
|
@ -150,7 +150,7 @@ async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage,
|
|||
"Error making request to Cohost for posts for project '{}': {:?}",
|
||||
project_id, e
|
||||
);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
return Err(ErrorResponse::InternalError(err));
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ async fn get_page_data(project_id: String, page: u64) -> Result<CohostPostsPage,
|
|||
#[cached(time = 60, result)]
|
||||
async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResponse> {
|
||||
let project_url = format!("{}{}", COHOST_ACCOUNT_API_URL, project_id);
|
||||
eprintln!("making request to {}", project_url);
|
||||
eprintln!("[INT] making request to {}", project_url);
|
||||
match CLIENT.get(project_url).send().await {
|
||||
Ok(v) => match v.status() {
|
||||
StatusCode::OK => match v.json::<CohostAccount>().await {
|
||||
|
@ -169,7 +169,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
|
|||
"Couldn't deserialize Cohost project '{}': {:?}",
|
||||
project_id, e
|
||||
);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
Err(ErrorResponse::InternalError(err))
|
||||
}
|
||||
},
|
||||
|
@ -179,7 +179,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
|
|||
"Didn't receive status code 200 for Cohost project '{}'; got {:?} instead.",
|
||||
project_id, s
|
||||
);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
Err(ErrorResponse::NotFound(err))
|
||||
}
|
||||
},
|
||||
|
@ -188,7 +188,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
|
|||
"Error making request to Cohost for project '{}': {:?}",
|
||||
project_id, e
|
||||
);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
Err(ErrorResponse::InternalError(err))
|
||||
}
|
||||
}
|
||||
|
@ -196,6 +196,7 @@ async fn get_project_data(project_id: String) -> Result<CohostAccount, ErrorResp
|
|||
|
||||
#[get("/<project>/originals.rss")]
|
||||
async fn syndication_originals_rss_route(project: String) -> Result<RssResponse, ErrorResponse> {
|
||||
eprintln!("[EXT] Request to /{}/originals.rss", project);
|
||||
let project_data = get_project_data(project.clone()).await?;
|
||||
let page_data = get_full_post_data(project.clone()).await?;
|
||||
Ok(RssResponse {
|
||||
|
@ -206,6 +207,7 @@ async fn syndication_originals_rss_route(project: String) -> Result<RssResponse,
|
|||
|
||||
#[get("/<project>/feed.rss")]
|
||||
async fn syndication_rss_route(project: String) -> Result<RssResponse, ErrorResponse> {
|
||||
eprintln!("[EXT] Request to /{}/feed.rss", project);
|
||||
let project_data = get_project_data(project.clone()).await?;
|
||||
let page_data = get_full_post_data(project.clone()).await?;
|
||||
Ok(RssResponse {
|
||||
|
@ -216,6 +218,7 @@ async fn syndication_rss_route(project: String) -> Result<RssResponse, ErrorResp
|
|||
|
||||
#[get("/<project>/<id>")]
|
||||
async fn post_md_route(project: String, id: u64) -> Result<MdResponse, ErrorResponse> {
|
||||
eprintln!("[EXT] Request to /{}/{}", project, id);
|
||||
let _project_data = get_project_data(project.clone()).await?;
|
||||
let post_data = get_post_from_page(project.clone(), id).await?;
|
||||
Ok(MdResponse {
|
||||
|
@ -227,12 +230,20 @@ async fn post_md_route(project: String, id: u64) -> Result<MdResponse, ErrorResp
|
|||
async fn webfinger_route(
|
||||
params: HashMap<String, String>,
|
||||
) -> Result<Json<CohostWebfingerResource>, ErrorResponse> {
|
||||
let mut url_params_string = String::new();
|
||||
for (k, v) in params.iter() {
|
||||
url_params_string.push_str(&format!("{}={}&", k, v));
|
||||
}
|
||||
eprintln!(
|
||||
"[EXT] Request to /.well_known/webfinger?{}",
|
||||
url_params_string
|
||||
);
|
||||
if params.len() != 1 {
|
||||
let err = format!(
|
||||
"Too may or too few parameters. Expected 1, got {}",
|
||||
params.len()
|
||||
);
|
||||
eprintln!("{}", err);
|
||||
eprintln!("[ERR] {}", err);
|
||||
return Err(ErrorResponse::InternalError(err));
|
||||
}
|
||||
if let Some(param) = params.iter().next() {
|
||||
|
|
Loading…
Reference in New Issue