switchgear_service_api/
service.rs1pub use axum::http::StatusCode;
2use std::error::Error;
3use std::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum ServiceErrorSource {
7 Upstream,
8 Downstream,
9 Internal,
10}
11
12impl fmt::Display for ServiceErrorSource {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 ServiceErrorSource::Upstream => write!(f, "Upstream"),
16 ServiceErrorSource::Downstream => write!(f, "Downstream"),
17 ServiceErrorSource::Internal => write!(f, "Internal"),
18 }
19 }
20}
21
22impl Error for ServiceErrorSource {}
23
24impl ServiceErrorSource {
25 pub fn to_http_status(&self) -> StatusCode {
26 match self {
27 ServiceErrorSource::Downstream => StatusCode::BAD_REQUEST,
28 ServiceErrorSource::Upstream => StatusCode::BAD_GATEWAY,
29 ServiceErrorSource::Internal => StatusCode::INTERNAL_SERVER_ERROR,
30 }
31 }
32}
33
34pub trait HasServiceErrorSource {
35 fn get_service_error_source(&self) -> ServiceErrorSource;
36}