Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling #176

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Node/src/mev_boost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,28 @@ impl MevBoost {

async fn post_constraints(&self, params: Value) -> Result<Value, Error> {
let client = Client::new();
// Send the POST request to the MEV Boost
let response = client
.post(self.url.clone() + "/eth/v1/builder/constraints")
.json(&params)
.send()
.await
.map_err(|e| anyhow::anyhow!("Failed to send message: {}", e))?;

let json: Value = response.json().await.unwrap();
.map_err(|e| anyhow::anyhow!("MEV Boost failed to send message: {}", e))?;

// Check the response status
if !response.status().is_success() {
return Err(anyhow::anyhow!(
"MEV Boost received non-success status: {}",
response.status()
));
}

// Attempt to parse the response as JSON
let json: Value = response
.json()
.await
.map_err(|e| anyhow::anyhow!("MEV Boost failed to parse JSON: {}", e))?;

Ok(json)
}

Expand Down