zoe_relay/
error.rs

1/// Standard service error types
2///
3/// Send over the wire as u8. Inspired by HTTP status codes.
4#[derive(Debug, thiserror::Error)]
5#[repr(u8)]
6pub enum ServiceError {
7    // 40-49 are for client errors
8    #[error("Authentication failed")]
9    AuthenticationFailed = 41, // 401 unauthorized in HTTP
10
11    #[error("Resource not found")]
12    ResourceNotFound = 44, // 404 not found in HTTP
13
14    #[error("Invalid service ID: {0}")]
15    InvalidServiceId(u8) = 40, // 400 bad request in HTTP
16
17    // 50-59 are for server errors
18    #[error("Unknown service")]
19    UnknownService = 51, // the service is not known
20
21    #[error("Service unavailable")]
22    ServiceUnavailable = 52, // the service is known but unavailable at this point
23}
24
25impl ServiceError {
26    /// Get the u8 discriminant value for this error
27    pub fn as_u8(&self) -> u8 {
28        match self {
29            ServiceError::InvalidServiceId(_) => 40,
30            ServiceError::AuthenticationFailed => 41,
31            ServiceError::ResourceNotFound => 44,
32            ServiceError::UnknownService => 51,
33            ServiceError::ServiceUnavailable => 52,
34        }
35    }
36}