1use axum::{response::{IntoResponse, Response}, http::StatusCode};
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum FlowError<E> {
7 #[error("Request dropped due to high load")]
8 Dropped,
9 #[error("FlowGuard semaphore closed")]
10 Closed,
11 #[error("Application error: {0}")]
12 AppError(#[from] E),
13}
14
15impl<E: IntoResponse> IntoResponse for FlowError<E> {
17 fn into_response(self) -> Response {
18 match self {
19 Self::Dropped => (StatusCode::SERVICE_UNAVAILABLE, "Service Overloaded - Try again later").into_response(),
20 Self::Closed => (StatusCode::INTERNAL_SERVER_ERROR, "FlowGuard Closed").into_response(),
21 Self::AppError(e) => e.into_response(),
22 }
23 }
24}