mirror of
https://github.com/actix/examples
synced 2024-12-18 00:13:57 +01:00
Fix an error in method wait
This commit is contained in:
parent
8371d77f7c
commit
397b8e22fa
@ -36,7 +36,7 @@ fn rpc_handler(
|
|||||||
let mut result = convention::Response::default();
|
let mut result = convention::Response::default();
|
||||||
result.id = reqjson.id.clone();
|
result.id = reqjson.id.clone();
|
||||||
|
|
||||||
match rpc_select(&app_state, reqjson.method.as_str()) {
|
match rpc_select(&app_state, reqjson.method.as_str(), reqjson.params) {
|
||||||
Ok(ok) => result.result = ok,
|
Ok(ok) => result.result = ok,
|
||||||
Err(e) => result.error = Some(e),
|
Err(e) => result.error = Some(e),
|
||||||
}
|
}
|
||||||
@ -47,16 +47,31 @@ fn rpc_handler(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rpc_select(app_state: &AppState, method: &str) -> Result<Value, convention::ErrorData> {
|
fn rpc_select(
|
||||||
|
app_state: &AppState,
|
||||||
|
method: &str,
|
||||||
|
params: Vec<Value>,
|
||||||
|
) -> Result<Value, convention::ErrorData> {
|
||||||
match method {
|
match method {
|
||||||
"ping" => {
|
"ping" => {
|
||||||
let r = app_state.network.read().unwrap().ping();
|
let r = app_state.network.read().unwrap().ping();
|
||||||
Ok(Value::from(r))
|
Ok(Value::from(r))
|
||||||
}
|
}
|
||||||
"wait" => match app_state.network.read().unwrap().wait(4).wait() {
|
"wait" => {
|
||||||
|
if params.len() != 1 || !params[0].is_u64() {
|
||||||
|
return Err(convention::ErrorData::std(-32602));
|
||||||
|
}
|
||||||
|
match app_state
|
||||||
|
.network
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.wait(params[0].as_u64().unwrap())
|
||||||
|
.wait()
|
||||||
|
{
|
||||||
Ok(ok) => Ok(Value::from(ok)),
|
Ok(ok) => Ok(Value::from(ok)),
|
||||||
Err(e) => Err(convention::ErrorData::new(500, &format!("{:?}", e)[..])),
|
Err(e) => Err(convention::ErrorData::new(500, &format!("{:?}", e)[..])),
|
||||||
},
|
}
|
||||||
|
}
|
||||||
"get" => {
|
"get" => {
|
||||||
let r = app_state.network.read().unwrap().get();
|
let r = app_state.network.read().unwrap().get();
|
||||||
Ok(Value::from(r))
|
Ok(Value::from(r))
|
||||||
|
Loading…
Reference in New Issue
Block a user