Skip to content

Commit

Permalink
Implement tide_disco::error::Error for builder::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinI committed Feb 16, 2024
1 parent 7ed5ba2 commit 855ad54
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ pub enum Error {
},
}

impl tide_disco::error::Error for Error {
fn catch_all(status: StatusCode, msg: String) -> Self {
Error::Custom {
message: msg,
status,
}
}

fn status(&self) -> StatusCode {
match self {
Error::Request { .. } => StatusCode::BadRequest,
Error::BlockAvailable { source, .. } | Error::BlockClaim { source, .. } => match source
{
BuildError::NotFound => StatusCode::NotFound,
BuildError::Missing => StatusCode::NotFound,
BuildError::Error { .. } => StatusCode::InternalServerError,
},
Error::Custom { .. } => StatusCode::InternalServerError,
}
}
}

pub fn define_api<State, Types: NodeType>(options: &Options) -> Result<Api<State, Error>, ApiError>
where
State: 'static + Send + Sync + ReadState,
Expand Down

0 comments on commit 855ad54

Please sign in to comment.