Skip to content

Commit

Permalink
fix: relayer errors should cause transport errors (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclx authored Nov 5, 2024
1 parent e76ce41 commit f9a0e15
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Method<Starknet> for ProposalRequest {
todo!()
}

fn decode(response: Vec<u8>) -> eyre::Result<Self::Returns> {
fn decode(_response: Vec<u8>) -> eyre::Result<Self::Returns> {
todo!()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Method<Starknet> for ProposalRequest {
todo!()
}

fn decode(response: Vec<u8>) -> eyre::Result<Self::Returns> {
fn decode(_response: Vec<u8>) -> eyre::Result<Self::Returns> {
todo!()
}
}
26 changes: 23 additions & 3 deletions crates/context/config/src/client/relayer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Cow;

use serde::{Deserialize, Serialize};
use thiserror::Error;
use url::Url;

use super::transport::{Operation, Transport, TransportRequest};
Expand Down Expand Up @@ -39,8 +40,22 @@ pub struct RelayRequest<'a> {
pub payload: Vec<u8>,
}

#[derive(Debug, Error)]
pub enum RelayerError {
#[error(transparent)]
Raw(#[from] reqwest::Error),
#[error(
"relayer response ({status}): {}",
body.is_empty().then_some("<empty>").unwrap_or(body)
)]
Response {
status: reqwest::StatusCode,
body: String,
},
}

impl Transport for RelayerTransport {
type Error = reqwest::Error;
type Error = RelayerError;

async fn send(
&self,
Expand All @@ -60,8 +75,13 @@ impl Transport for RelayerTransport {
.send()
.await?;

// todo! check response.status code
if !response.status().is_success() {
return Err(RelayerError::Response {
status: response.status(),
body: response.text().await?,
});
}

response.bytes().await.map(Into::into)
response.bytes().await.map(Into::into).map_err(Into::into)
}
}

0 comments on commit f9a0e15

Please sign in to comment.