polish
This commit is contained in:
parent
6963a88602
commit
e7570a4c20
11 changed files with 138 additions and 5 deletions
23
orders/error_handler.go
Normal file
23
orders/error_handler.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue