From d2073740338d58ef91eba85f8f44157d475117f9 Mon Sep 17 00:00:00 2001 From: Jan David Date: Mon, 13 Jun 2022 18:08:12 +0200 Subject: [PATCH] Add configuration and data errors (#23) Workflows can fail if either the configuration is not valid or they are missing data in the webhook payload. New error variants have been added for both cases. --- src/workflow.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/workflow.rs b/src/workflow.rs index c96d302..e5902d8 100644 --- a/src/workflow.rs +++ b/src/workflow.rs @@ -11,17 +11,25 @@ pub trait Workflow: Debug + Sync + Send { async fn process(&self, event: Event) -> Result; } -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Error)] +#[derive(Debug, Error)] pub enum WorkflowError { + #[error("configuration was not valid")] + Configuration, + #[error("{0}")] - Unknown(String), + MissingData(String), + + #[error(transparent)] + UnexpectedError(#[from] anyhow::Error), } impl IntoResponse for WorkflowError { fn into_response(self) -> Response { match self { - WorkflowError::Unknown(error) => { - (StatusCode::INTERNAL_SERVER_ERROR, error).into_response() + WorkflowError::Configuration => StatusCode::OK.into_response(), + WorkflowError::MissingData(error) => (StatusCode::BAD_REQUEST, error).into_response(), + WorkflowError::UnexpectedError(error) => { + (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response() } } }