]> Untitled Git - lemmy.git/commitdiff
Guard CreateCommunity, represent impossible error with Infallible
authorasonix <asonix@asonix.dog>
Mon, 20 Apr 2020 17:31:22 +0000 (12:31 -0500)
committerasonix <asonix@asonix.dog>
Mon, 20 Apr 2020 17:31:22 +0000 (12:31 -0500)
server/src/routes/api.rs
server/src/routes/websocket.rs
server/src/websocket/server.rs

index 025c6e0a70ac9d47c09b8fa870fa6d7073dcc497..629bd49da87d89a955fe4277988bc9a7aee5d1f6 100644 (file)
@@ -40,10 +40,15 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
           .route(web::get().to(route_get::<Search>)),
       )
       // Community
+      .service(
+        web::resource("/community")
+          .guard(guard::Post())
+          .wrap(rate_limit.post())
+          .route(web::post().to(route_post::<CreateCommunity>)),
+      )
       .service(
         web::scope("/community")
           .wrap(rate_limit.message())
-          .route("", web::post().to(route_post::<CreateCommunity>))
           .route("", web::get().to(route_get::<GetCommunity>))
           .route("", web::put().to(route_post::<EditCommunity>))
           .route("/list", web::get().to(route_get::<ListCommunities>))
index eb1575906224dd8dfe3ebf57545191dafa937e1a..e1efdc0f5ce6dc16180c919ac4427d81d0aafe37 100644 (file)
@@ -120,7 +120,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WSSession {
           .then(|res, _, ctx| {
             match res {
               Ok(Ok(res)) => ctx.text(res),
-              Ok(Err(e)) => error!("{}", e),
+              Ok(Err(e)) => match e {},
               Err(e) => error!("{}", &e),
             }
             actix::fut::ready(())
index d16ecf854ab9993b1530ddfe3694dfab5484cba9..cd78bbc7f875df9abc1e76e1e8ad3ec2807d7942 100644 (file)
@@ -38,7 +38,7 @@ pub struct Disconnect {
 
 /// The messages sent to websocket clients
 #[derive(Serialize, Deserialize, Message)]
-#[rtype(result = "Result<String, failure::Error>")]
+#[rtype(result = "Result<String, std::convert::Infallible>")]
 pub struct StandardMessage {
   /// Id of the client session
   pub id: ConnectionId,
@@ -905,6 +905,7 @@ where
   match op2 {
     UserOperation::Register => rate_limiter.register().wrap(ip, fut).await,
     UserOperation::CreatePost => rate_limiter.post().wrap(ip, fut).await,
+    UserOperation::CreateCommunity => rate_limiter.post().wrap(ip, fut).await,
     _ => rate_limiter.message().wrap(ip, fut).await,
   }
 }
@@ -963,7 +964,7 @@ impl Handler<Disconnect> for ChatServer {
 
 /// Handler for Message message.
 impl Handler<StandardMessage> for ChatServer {
-  type Result = ResponseFuture<Result<String, failure::Error>>;
+  type Result = ResponseFuture<Result<String, std::convert::Infallible>>;
 
   fn handle(&mut self, msg: StandardMessage, ctx: &mut Context<Self>) -> Self::Result {
     let fut = self.parse_json_message(msg, ctx);