almost correct errors

This commit is contained in:
Bryan Stitt 2022-05-12 21:53:24 +00:00
parent 82aff37054
commit 8e499a1735
2 changed files with 21 additions and 5 deletions

@ -308,6 +308,7 @@ impl Web3ProxyApp {
response
}
Err(e) => {
// TODO: move this to a helper function?
let code;
let message: String;
let data;

@ -4,6 +4,8 @@ mod connection;
mod connections;
mod jsonrpc;
use jsonrpc::{JsonRpcErrorData, JsonRpcForwardedResponse};
use serde_json::value::RawValue;
use std::fs;
use std::sync::atomic::{self, AtomicUsize};
use std::sync::Arc;
@ -72,11 +74,24 @@ fn handle_anyhow_errors<T: warp::Reply>(
) -> warp::http::Response<warp::hyper::Body> {
match res {
Ok(r) => r.into_response(),
Err(e) => warp::reply::with_status(
// TODO: json error
format!("{}", e),
warp::http::StatusCode::INTERNAL_SERVER_ERROR,
)
Err(e) => {
let e = JsonRpcForwardedResponse {
jsonrpc: "2.0".to_string(),
// TODO: what id can we use? how do we make sure it gets attached to this?
id: RawValue::from_string("0".to_string()).unwrap(),
result: None,
error: Some(JsonRpcErrorData {
code: -32099,
message: format!("{:?}", e),
data: None,
}),
};
warp::reply::with_status(
serde_json::to_string(&e).unwrap(),
warp::http::StatusCode::INTERNAL_SERVER_ERROR,
)
}
.into_response(),
}
}