Commit a8e3d8d2 authored by Daniel Edgecumbe's avatar Daniel Edgecumbe

backend: Return JSON errors rather than silly stuff like 'wat'

parent 3b15890a
Pipeline #307 passed with stages
in 2 minutes and 5 seconds
......@@ -87,7 +87,9 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
if raw_args.len() < 2 || raw_args[1].len() == 0 { // e.g. "/"
log(&format!("INVALID: {}", x));
*response.body_mut() = Body::from("do you mind");
*response.body_mut() = Body::from(
"{\"result\": null, \"error\": \"go away\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -98,7 +100,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a blockinfo innit");
if raw_args.len() < 3 {
*response.body_mut() = Body::from(
"needs more arguments lad"
"{\"result\": null, \"error\": \"needs more arguments lad\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -136,7 +138,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a peerinfo innit");
if raw_args.len() > 2 {
*response.body_mut() = Body::from(
"too many arguments lad"
"{\"result\": null, \"error\": \"too many arguments lad\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -166,7 +168,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a blocktemplate innit");
if raw_args.len() > 2 {
*response.body_mut() = Body::from(
"too many arguments lad"
"{\"result\": null, \"error\": \"too many arguments lad\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -195,7 +197,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a mempoolbins innit");
if raw_args.len() > 2 {
*response.body_mut() = Body::from(
"too many arguments lad"
"{\"result\": null, \"error\": \"too many arguments lad\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -224,7 +226,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a nettotals innit");
if raw_args.len() > 2 {
*response.body_mut() = Body::from(
"too many arguments lad"
"{\"result\": null, \"error\": \"too many arguments lad\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -253,7 +255,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a mempoolbinsrange innit");
if raw_args.len() < 3 {
*response.body_mut() = Body::from(
"not enough arguments lad"
"{\"result\": null, \"error\": \"not enough arguments lad\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -316,7 +318,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
eprintln!("ey lads its a nettotalsrange innit");
if raw_args.len() < 3 {
*response.body_mut() = Body::from(
"not enough arguments lad"
"{\"result\": null, \"error\": \"not enough args\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
}
......@@ -324,7 +326,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
Ok(x) => x,
Err(_) => {
*response.body_mut() = Body::from(
"stop it"
"{\"result\": null, \"error\": \"not an integer\", \"id\": \"na\"}\n"
);
return Box::new(futures::future::ok(response));
},
......@@ -381,7 +383,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
Some(x) => x,
None => {
log(&format!("FORBIDDEN: {}", x));
*response.body_mut() = Body::from("nah\n");
*response.body_mut() = Body::from("{\"result\": null, \"error\": \"ERROR: denied by backend\", \"id\": \"na\"}\n");
return Box::new(futures::future::ok(response));
},
};
......@@ -392,7 +394,7 @@ pub fn server_get(x: &str, pool: &PgPool, rpc_auth: &str, rpc_addr: &str) -> Box
} else if raw_args.len() > (2 + argument_cap) {
log(&format!("TOO_MANY_PARAMS: {}", x));
*response.body_mut() = Body::from("nah m8\n");
*response.body_mut() = Body::from("{\"result\": null, \"error\": \"ERROR: denied by backend\", \"id\": \"na\"}\n");
return Box::new(futures::future::ok(response));
} else {
let mut tparams: Vec<BitcoinRPCParameter> = Vec::new();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment