Lines
100 %
Functions
75 %
Branches
use axum::{
http::{HeaderValue, StatusCode, header},
response::{Html, IntoResponse, Response},
};
/// The 422 answer for a shared form: the re-rendered form replaces the
/// element `#nf-<form>` (see `form_render::render_form`).
pub fn form_invalid(form: &forms::Form, html: String) -> Response {
let Ok(target) = HeaderValue::from_str(&format!("#nf-{}", form.name)) else {
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
(
StatusCode::UNPROCESSABLE_ENTITY,
[
(header::HeaderName::from_static("hx-retarget"), target),
header::HeaderName::from_static("hx-reswap"),
HeaderValue::from_static("outerHTML"),
),
],
Html(html),
)
.into_response()
}
#[cfg(test)]
mod tests;