From 855ad547db10c22323df98ed8b84a704a54eac9b Mon Sep 17 00:00:00 2001 From: Artemii Gerasimovich Date: Thu, 15 Feb 2024 20:41:08 +0100 Subject: [PATCH] Implement `tide_disco::error::Error` for `builder::Error` --- src/builder.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index c69c2eb..7291e14 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -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(options: &Options) -> Result, ApiError> where State: 'static + Send + Sync + ReadState,