Skip to content

Commit

Permalink
format binding error into response
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu committed Nov 15, 2024
1 parent 116223a commit ef91314
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/middleware/req_validator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middleware

import (
"fmt"
"net/http"
"reflect"

Expand Down Expand Up @@ -37,7 +38,7 @@ func ValidateRequestBody(structType reflect.Type) echo.MiddlewareFunc {
reqStruct := reflect.New(structType)

if err := c.Bind(reqStruct.Interface()); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid request body.")
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid request body: %v", err))
}

if err := c.Validate(reqStruct.Interface()); err != nil {
Expand Down

0 comments on commit ef91314

Please sign in to comment.