~repos /gromer

#golang#htmx#ssr

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.


67190124 Peter John

tag: v1.2.1

v1.2.1

3 years ago
fix validation errors again
Files changed (1) hide show
  1. http.go +11 -9
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
- validationErrors, ok := err.(validator.ValidationErrors)
76
+ validationErrors, ok := eris.Cause(err).(validator.ValidationErrors)
76
- if ok {
77
+ if ok {
77
- w.Header().Set("Content-Type", "application/json")
78
+ w.Header().Set("Content-Type", "application/json")
78
- w.WriteHeader(status)
79
+ w.WriteHeader(status)
79
- data, _ := json.Marshal(gsx.M{
80
+ data, _ := json.Marshal(gsx.M{
80
- "error": GetValidationError(validationErrors),
81
+ "error": GetValidationError(validationErrors),
81
- })
82
+ })
82
- w.Write(data)
83
+ w.Write(data)
83
- return
84
+ return
85
+ }
84
86
  }
85
87
  w.Header().Set("Content-Type", "text/html")
86
88
  w.WriteHeader(status) // always write status last