1use axum::{
2 http::StatusCode,
3 response::{IntoResponse, Json, Response},
4};
5
6pub enum AppError {
8 NotFound(String),
9 BadRequest(String),
10 Internal(String),
11}
12
13impl IntoResponse for AppError {
14 fn into_response(self) -> Response {
15 let (status, message) = match self {
16 Self::NotFound(msg) => (StatusCode::NOT_FOUND, msg),
17 Self::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg),
18 Self::Internal(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg),
19 };
20 (status, Json(serde_json::json!({ "error": message }))).into_response()
21 }
22}
23
24impl From<flow_core::FlowError> for AppError {
25 fn from(err: flow_core::FlowError) -> Self {
26 Self::Internal(err.to_string())
27 }
28}
29
30pub type AppResult<T> = Result<T, AppError>;