Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Add configuration and data errors (#23)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jdno authored Jun 13, 2022
1 parent 064b731 commit d207374
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ pub trait Workflow: Debug + Sync + Send {
async fn process(&self, event: Event) -> Result<serde_json::Value, WorkflowError>;
}

#[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()
}
}
}
Expand Down

0 comments on commit d207374

Please sign in to comment.