From d50e6e54975a3a39ebfb252676d7f7857d588cab Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 May 2021 18:04:23 +0300 Subject: More descriptive error handling and more descriptive TODOs --- src/micropub/post.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/micropub/post.rs') diff --git a/src/micropub/post.rs b/src/micropub/post.rs index 69b74e9..c1efd61 100644 --- a/src/micropub/post.rs +++ b/src/micropub/post.rs @@ -176,11 +176,13 @@ async fn new_post(req: Request>, body: serde_jso }, Err(err) => return Ok(err.into()) } - // WARNING: WRITE BOUNDARY - //let mut storage = RwLockUpgradableReadGuard::upgrade(storage).await; + if let Err(err) = storage.put_post(&post).await { return error_json!(500, "database_error", format!("{}", err)) } + + // It makes sense to use a loop here, because you wouldn't post to a hundred channels at once + // Mostly one or two, and even those ones will be the ones picked for you by software for channel in post["properties"]["channel"] .as_array().unwrap().iter() .map(|i| i.as_str().unwrap_or("").to_string()) @@ -350,7 +352,7 @@ async fn post_process_new_post(req: Request>, po // I wonder why could it even happen except in case of a database disconnection? } // 3. Send WebSub notifications - // TODO + // TODO WebSub support // 4. Send webmentions // We'll need the bodies here to get their endpoints @@ -373,15 +375,17 @@ async fn post_process_new_post(req: Request>, po serde_urlencoded::to_string(vec![("source", source), ("target", &target.to_string())]) .expect("Couldn't construct webmention form") ).send().await; - // TODO improve error handling - if let Ok(response) = response { - if response.status() == 200 || response.status() == 201 || response.status() == 202 { + match response { + Ok(response) => if response.status() == 200 || response.status() == 201 || response.status() == 202 { Ok(()) } else { + error!("Sending webmention for {} to {} failed: Endpoint replied with HTTP {}", target, endpoint, response.status()); + Err(()) + } + Err(err) => { + error!("Sending webmention for {} to {} failed: {}", target, endpoint, err); Err(()) } - } else { - Err(()) } }).buffer_unordered(3).collect::>().await; } @@ -467,7 +471,7 @@ async fn process_form(req: Request>, form: Vec<( None => return error_json!(400, "invalid_request", "Please provide an `url` to delete.") } } else { - return error_json!(400, "invalid_request", "This action is not supported in form-encoded mode. (JSON requests support more actions, use them!)") + return error_json!(400, "invalid_request", "This action is not supported in form-encoded mode. (JSON requests support more actions, use JSON!)") } } -- cgit 1.4.1