~repos /gromer
git clone https://pyrossh.dev/repos/gromer.git
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
fix validation errors again
http.go
CHANGED
|
@@ -72,15 +72,17 @@ func getFunctionName(temp interface{}) string {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
func RespondError(w http.ResponseWriter, r *http.Request, status int, err error) {
|
|
75
|
+
if r.Header.Get("Content-Type") == "application/json" {
|
|
75
|
-
|
|
76
|
+
validationErrors, ok := eris.Cause(err).(validator.ValidationErrors)
|
|
76
|
-
|
|
77
|
+
if ok {
|
|
77
|
-
|
|
78
|
+
w.Header().Set("Content-Type", "application/json")
|
|
78
|
-
|
|
79
|
+
w.WriteHeader(status)
|
|
79
|
-
|
|
80
|
+
data, _ := json.Marshal(gsx.M{
|
|
80
|
-
|
|
81
|
+
"error": GetValidationError(validationErrors),
|
|
81
|
-
|
|
82
|
+
})
|
|
82
|
-
|
|
83
|
+
w.Write(data)
|
|
83
|
-
|
|
84
|
+
return
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
w.Header().Set("Content-Type", "text/html")
|
|
86
88
|
w.WriteHeader(status) // always write status last
|