This commit is contained in:
bronku 2026-11-08 20:32:49 +01:00
parent 6963a88602
commit e7570a4c20
11 changed files with 138 additions and 5 deletions

23
orders/error_handler.go Normal file
View file

@ -0,0 +1,23 @@
package orders
import (
"net/http"
"piekarnikgosipl/html"
)
func errorMessages(err error) []string {
if j, ok := err.(interface{ Unwrap() []error }); ok {
var out []string
for _, e := range j.Unwrap() {
out = append(out, e.Error())
}
return out
}
return []string{err.Error()}
}
func writeErrors(w http.ResponseWriter, r *http.Request, status int, msgs ...string) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(status)
html.FormErrors(msgs).Render(r.Context(), w)
}