use std::str::FromStr;
use axum::handler::HandlerWithoutStateExt;
use http::StatusCode;
use serde::{Deserialize, Serialize};
use crate::error_responders::default_body_for_status;
use crate::target::IntoTarget;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ReturnConfig {
status: String,
body: Option<String>,
}
pub fn from_config(config: ReturnConfig) -> anyhow::Result<impl IntoTarget> {
let code = StatusCode::from_str(&config.status)?;
let text = config.body.unwrap_or(default_body_for_status(&code));
Ok((move || async move { (code, text) }).into_service())
}