diff --git a/daemon/src/routes_maker.rs b/daemon/src/routes_maker.rs index a2d2d7f..d092738 100644 --- a/daemon/src/routes_maker.rs +++ b/daemon/src/routes_maker.rs @@ -148,58 +148,35 @@ pub fn post_cfd_action( action: CfdAction, cfd_action_channel: &State>>, _auth: Authenticated, -) -> Result, status::BadRequest<()>> { +) -> Result, status::Custom<()>> { use maker_cfd::CfdAction::*; - match action { - CfdAction::AcceptOrder => { - cfd_action_channel - .do_send(AcceptOrder { order_id: id }) - .expect("actor to always be available"); - } - CfdAction::RejectOrder => { - cfd_action_channel - .do_send(RejectOrder { order_id: id }) - .expect("actor to always be available"); - } + let result = match action { + CfdAction::AcceptOrder => cfd_action_channel.do_send(AcceptOrder { order_id: id }), + CfdAction::RejectOrder => cfd_action_channel.do_send(RejectOrder { order_id: id }), CfdAction::AcceptSettlement => { - cfd_action_channel - .do_send(AcceptSettlement { order_id: id }) - .expect("actor to always be available"); + cfd_action_channel.do_send(AcceptSettlement { order_id: id }) } CfdAction::RejectSettlement => { - cfd_action_channel - .do_send(RejectSettlement { order_id: id }) - .expect("actor to always be available"); - } - - CfdAction::AcceptRollOver => { - cfd_action_channel - .do_send(AcceptRollOver { order_id: id }) - .expect("actor to always be available"); - } - CfdAction::RejectRollOver => { - cfd_action_channel - .do_send(RejectRollOver { order_id: id }) - .expect("actor to always be available"); - } - CfdAction::Commit => { - cfd_action_channel - .do_send(Commit { order_id: id }) - .expect("actor to always be available"); + cfd_action_channel.do_send(RejectSettlement { order_id: id }) } + CfdAction::AcceptRollOver => cfd_action_channel.do_send(AcceptRollOver { order_id: id }), + CfdAction::RejectRollOver => cfd_action_channel.do_send(RejectRollOver { order_id: id }), + CfdAction::Commit => cfd_action_channel.do_send(Commit { order_id: id }), CfdAction::Settle => { tracing::error!("Collaborative settlement can only be triggered by taker"); - return Err(status::BadRequest(None)); + return Err(status::Custom(Status::BadRequest, ())); } CfdAction::RollOver => { tracing::error!("RollOver proposal can only be triggered by taker"); - return Err(status::BadRequest(None)); + return Err(status::Custom(Status::BadRequest, ())); } - } + }; - Ok(status::Accepted(None)) + result + .map(|()| status::Accepted(None)) + .map_err(|_| status::Custom(Status::InternalServerError, ())) } #[rocket::get("/alive")]