Skip to content

Commit

Permalink
Change to error codes after reading seanmonstar/warp#712 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlvandenhout committed May 16, 2021
1 parent 729cee6 commit 37d6d02
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/handle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::Arc;
use tokio::sync::Mutex;
use serde::{Deserialize, Serialize};
use warp::http::StatusCode;
use iota_streams::app_channels::api::tangle::{
Author,
Subscriber,
Address,
};
use iota_streams::app::transport::tangle::{
PAYLOAD_BYTES,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub async fn connect(
) -> Result<impl warp::Reply, std::convert::Infallible> {
let mut optional_url = optional_url.lock().await;
optional_url.replace(connect_options.url);
Ok(warp::reply())
Ok(StatusCode::OK)
}


Expand Down Expand Up @@ -91,32 +91,39 @@ pub async fn participate(
.await
.replace(participant);

Ok(warp::reply())
Ok(StatusCode::OK)
} else {
Err(warp::reject())
Ok(StatusCode::CONFLICT)
}
}


pub async fn interact(
optional_participant: Arc<Mutex<Option<Participant>>>,
interact_options: InteractOptions,
) -> core::result::Result<impl warp::Reply, warp::Rejection> {
) -> core::result::Result<impl warp::Reply, std::convert::Infallible> {
let mut optional_participant = optional_participant.lock().await;

if let Some(participant) = optional_participant.as_mut() {
if let Participant::Author(author) = participant {
match interact_options {
InteractOptions::Announce => {
// BREAKING:
// author.send_announce().await;
Ok(warp::reply())
}
}
// // BREAKING:
// match author.send_announce().await {
// Ok(address) => {
// println!("{}", address);
// },
// Err(error) => {
// println!("{}", error);
// }
// };
},
};
Ok(StatusCode::OK)
} else {
Err(warp::reject())
Ok(StatusCode::BAD_REQUEST)
}
} else {
Err(warp::reject())
Ok(StatusCode::CONFLICT)
}
}

0 comments on commit 37d6d02

Please sign in to comment.