don't panic if param is not set

This commit is contained in:
Bryan Stitt 2023-03-09 09:32:30 -08:00
parent d7a843cdc5
commit b480e92259
2 changed files with 6 additions and 2 deletions

View File

@ -1493,7 +1493,9 @@ impl Web3ProxyApp {
match &request.params {
Some(serde_json::Value::Array(params)) => {
// TODO: make a struct and use serde conversion to clean this up
if params.len() != 1 || !params[0].is_string() {
if params.len() != 1
|| !params.get(0).map(|x| x.is_string()).unwrap_or(false)
{
// TODO: what error code?
return Ok((
JsonRpcForwardedResponse::from_str(

View File

@ -177,7 +177,9 @@ pub async fn block_needed(
// TODO: think about this more
// TODO: jsonrpc has a specific code for this
// TODO: this shouldn't be a 500. this should be a 400. 500 will make haproxy retry a bunch
let obj = params[0]
let obj = params
.get_mut(0)
.ok_or_else(|| anyhow::anyhow!("invalid format. no params"))?
.as_object_mut()
.ok_or_else(|| anyhow::anyhow!("invalid format"))?;