Browse Source

Don't expose panicking code paths to the user

An actor not being reachable is a bad internal state but it should
never lead to an actual panic.
testing
Thomas Eizinger 3 years ago
parent
commit
7c8d5e110b
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 53
      daemon/src/routes_maker.rs

53
daemon/src/routes_maker.rs

@ -148,58 +148,35 @@ pub fn post_cfd_action(
action: CfdAction,
cfd_action_channel: &State<Box<dyn MessageChannel<maker_cfd::CfdAction>>>,
_auth: Authenticated,
) -> Result<status::Accepted<()>, status::BadRequest<()>> {
) -> Result<status::Accepted<()>, 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")]

Loading…
Cancel
Save