Something went wrong. Try again.
My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152//! Maps `fil_core::Error` onto HTTP responses for the API server.use axum::{http::StatusCode, response::IntoResponse};pub enum ApiError { Kasten(fil_core::Error), Serialization(serde_json::Error), Io(std::io::Error), NotFound(String), BadRequest(String),}
impl From<std::io::Error> for ApiError { fn from(err: std::io::Error) -> Self { Self::Io(err) }}
impl From<fil_core::Error> for ApiError { fn from(err: fil_core::Error) -> Self { Self::Kasten(err) }}
impl From<serde_json::Error> for ApiError { fn from(err: serde_json::Error) -> Self { Self::Serialization(err) }}
impl IntoResponse for ApiError { fn into_response(self) -> axum::response::Response { match self { Self::Kasten(err) => { let status = match &err { fil_core::Error::GroupDoesNotExist => StatusCode::NOT_FOUND, fil_core::Error::InvalidDueDate { .. } | fil_core::Error::InvalidPriority => { StatusCode::BAD_REQUEST } _ => StatusCode::INTERNAL_SERVER_ERROR, };
(status, err.to_string()).into_response() } Self::Serialization(err) => { (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response() } Self::Io(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(), Self::NotFound(msg) => (StatusCode::NOT_FOUND, msg).into_response(), Self::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg).into_response(), } }}