azure_functions_durable/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4/// Represents a Durable Functions HTTP client error.
5#[derive(Debug, Clone, PartialEq)]
6pub enum ClientError {
7    /// Orchestration instance is in a failed or terminated state.
8    InstanceFailedOrTerminated,
9    /// Orchestration instance is in a completed or failed state.
10    InstanceCompletedOrFailed,
11    /// The orchestration instance was not found.
12    InstanceNotFound,
13    /// The request contained invalid JSON data.
14    BadRequest,
15    /// The specified orchestrator function doesn't exist or the request contained invalid JSON data.
16    BadCreateRequest,
17    /// The request failed due to an exception while processing the request.
18    InternalServerError,
19    /// The error is a message.
20    Message(String),
21}
22
23impl Display for ClientError {
24    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
25        match self {
26            Self::InstanceFailedOrTerminated => write!(f, "theinstance failed or was terminated"),
27            Self::InstanceCompletedOrFailed => write!(f, "instance completed or failed"),
28            Self::InstanceNotFound => {
29                write!(f, "instance doesn't exist or has not started running")
30            }
31            Self::BadRequest => write!(f, "request content was not valid JSON"),
32            Self::BadCreateRequest => write!(f, "the specified orchestrator function doesn't exist, the specified instance ID was not valid, or request content was not valid JSON"),
33            Self::InternalServerError => write!(f, "internal server error"),
34            Self::Message(msg) => write!(f, "{}", msg),
35        }
36    }
37}
38
39impl Error for ClientError {
40    fn source(&self) -> Option<&(dyn Error + 'static)> {
41        None
42    }
43}