about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-05-09 18:04:23 +0300
committerVika <vika@fireburn.ru>2021-05-09 18:04:23 +0300
commitd50e6e54975a3a39ebfb252676d7f7857d588cab (patch)
tree4df16a374cdeb4047d80e05b1a678f91f68d9ff9
parent002dc24c1440ad1d1fab0fc901fb0d6ff457b7a2 (diff)
downloadkittybox-d50e6e54975a3a39ebfb252676d7f7857d588cab.tar.zst
More descriptive error handling and more descriptive TODOs
-rw-r--r--src/micropub/get.rs2
-rw-r--r--src/micropub/post.rs22
2 files changed, 15 insertions, 9 deletions
diff --git a/src/micropub/get.rs b/src/micropub/get.rs
index 2b367fd..e106883 100644
--- a/src/micropub/get.rs
+++ b/src/micropub/get.rs
@@ -64,6 +64,8 @@ where
                 })).build())
             }
         },
+        // TODO: ?q=food, ?q=geo, ?q=contacts
+        // Depends on indexing posts
         // Errors
         "" => Ok(Response::builder(400).body(json!({
             "error": "invalid_request",
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<S: Storage>(req: Request<ApplicationState<S>>, 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<S: Storage>(req: Request<ApplicationState<S>>, 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<S: Storage>(req: Request<ApplicationState<S>>, 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::<Vec<_>>().await;
 }
@@ -467,7 +471,7 @@ async fn process_form<S: Storage>(req: Request<ApplicationState<S>>, 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!)")
         }
     }