From 4a9c3748cdd3a87ea2c4b6d03c1af789136a9b42 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Fri, 5 May 2023 10:57:48 +0200 Subject: [PATCH] Guard a StatusUnprocessableEntity with check for HTMx request Otherwise, HTMx would just ignore the HTML returned by the server and dispatch an error. --- pkg/products.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/products.go b/pkg/products.go index 9b990a1..caeb174 100644 --- a/pkg/products.go +++ b/pkg/products.go @@ -137,7 +137,9 @@ func HandleUpdateProduct(w http.ResponseWriter, r *http.Request, params httprout } slug := params[0].Value if !form.Validate() { - w.WriteHeader(http.StatusUnprocessableEntity) + if !IsHTMxRequest(r) { + w.WriteHeader(http.StatusUnprocessableEntity) + } mustRenderEditProductForm(w, r, slug, form) return }