fix(api): don't panic if PATCH /users/@me does not have "fields" set
This commit is contained in:
parent
59a1a3fb9b
commit
6cc4d4c41d
1 changed files with 14 additions and 12 deletions
|
@ -71,20 +71,22 @@ func (s *Server) patchUser(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// max 25 fields
|
if (req.Fields) != nil {
|
||||||
if len(*req.Fields) > db.MaxFields {
|
// max 25 fields
|
||||||
return server.APIError{
|
if len(*req.Fields) > db.MaxFields {
|
||||||
Code: server.ErrBadRequest,
|
|
||||||
Details: fmt.Sprintf("Too many fields (max %d, current %d)", db.MaxFields, len(*req.Fields)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate all fields
|
|
||||||
for i, field := range *req.Fields {
|
|
||||||
if s := field.Validate(); s != "" {
|
|
||||||
return server.APIError{
|
return server.APIError{
|
||||||
Code: server.ErrBadRequest,
|
Code: server.ErrBadRequest,
|
||||||
Details: fmt.Sprintf("field %d: %s", i, s),
|
Details: fmt.Sprintf("Too many fields (max %d, current %d)", db.MaxFields, len(*req.Fields)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate all fields
|
||||||
|
for i, field := range *req.Fields {
|
||||||
|
if s := field.Validate(); s != "" {
|
||||||
|
return server.APIError{
|
||||||
|
Code: server.ErrBadRequest,
|
||||||
|
Details: fmt.Sprintf("field %d: %s", i, s),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue