bouncer/internal/admin/error.go
William Petit e66938f1d3
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
feat: initial commit
2023-05-21 22:27:25 +02:00

32 lines
644 B
Go

package admin
import (
"fmt"
"net/http"
"forge.cadoles.com/cadoles/bouncer/internal/schema"
"gitlab.com/wpetit/goweb/api"
)
const ErrCodeAlreadyExist api.ErrorCode = "already-exist"
func invalidDataErrorResponse(w http.ResponseWriter, r *http.Request, err *schema.InvalidDataError) {
keyErrors := err.KeyErrors()
message := ""
for idx, err := range keyErrors {
if idx != 0 {
message += ", "
}
message += fmt.Sprintf("Path [%s]: %s", err.PropertyPath, err.Message)
}
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, &struct {
Message string `json:"message"`
}{
Message: message,
})
return
}