Guard a StatusUnprocessableEntity with check for HTMx request

Otherwise, HTMx would just ignore the HTML returned by the server and
dispatch an error.
This commit is contained in:
jordi fita mas 2023-05-05 10:57:48 +02:00
parent 73497eb051
commit 4a9c3748cd
1 changed files with 3 additions and 1 deletions

View File

@ -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
}