fix(backend): return 400 error on bad request, not 500
This commit is contained in:
parent
1ebbeebdcb
commit
fb8733befa
3 changed files with 11 additions and 11 deletions
|
@ -65,15 +65,15 @@ func (s *Server) createMember(w http.ResponseWriter, r *http.Request) (err error
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("name", &cmr.Names); err != nil {
|
if err := validateSlicePtr("name", &cmr.Names); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("pronoun", &cmr.Pronouns); err != nil {
|
if err := validateSlicePtr("pronoun", &cmr.Pronouns); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("field", &cmr.Fields); err != nil {
|
if err := validateSlicePtr("field", &cmr.Fields); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := s.DB.Begin(ctx)
|
tx, err := s.DB.Begin(ctx)
|
||||||
|
@ -175,7 +175,7 @@ func validateSlicePtr[T validator](typ string, slice *[]T) *server.APIError {
|
||||||
if s := pronouns.Validate(); s != "" {
|
if s := pronouns.Validate(); s != "" {
|
||||||
return &server.APIError{
|
return &server.APIError{
|
||||||
Code: server.ErrBadRequest,
|
Code: server.ErrBadRequest,
|
||||||
Details: fmt.Sprintf("%s %d: %s", typ, i, s),
|
Details: fmt.Sprintf("%s %d: %s", typ, i+1, s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,15 +115,15 @@ func (s *Server) patchMember(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("name", req.Names); err != nil {
|
if err := validateSlicePtr("name", req.Names); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("pronoun", req.Pronouns); err != nil {
|
if err := validateSlicePtr("pronoun", req.Pronouns); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("field", req.Fields); err != nil {
|
if err := validateSlicePtr("field", req.Fields); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
// update avatar
|
// update avatar
|
||||||
|
|
|
@ -89,15 +89,15 @@ func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("name", req.Names); err != nil {
|
if err := validateSlicePtr("name", req.Names); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("pronoun", req.Pronouns); err != nil {
|
if err := validateSlicePtr("pronoun", req.Pronouns); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSlicePtr("field", req.Fields); err != nil {
|
if err := validateSlicePtr("field", req.Fields); err != nil {
|
||||||
return err
|
return *err
|
||||||
}
|
}
|
||||||
|
|
||||||
// update avatar
|
// update avatar
|
||||||
|
@ -250,7 +250,7 @@ func validateSlicePtr[T validator](typ string, slice *[]T) *server.APIError {
|
||||||
if s := pronouns.Validate(); s != "" {
|
if s := pronouns.Validate(); s != "" {
|
||||||
return &server.APIError{
|
return &server.APIError{
|
||||||
Code: server.ErrBadRequest,
|
Code: server.ErrBadRequest,
|
||||||
Details: fmt.Sprintf("%s %d: %s", typ, i, s),
|
Details: fmt.Sprintf("%s %d: %s", typ, i+1, s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue