Skip to content

Commit

Permalink
admin: Write proper status on invalid requests (#4569) (fix #4561)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintbomb27 authored Feb 11, 2022
1 parent 1d0425b commit 07c7dc6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,16 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {

parts := strings.Split(idPath, "/")
if len(parts) < 3 || parts[2] == "" {
return fmt.Errorf("request path is missing object ID")
return APIError{
HTTPStatus: http.StatusBadRequest,
Err: fmt.Errorf("request path is missing object ID"),
}
}
if parts[0] != "" || parts[1] != "id" {
return fmt.Errorf("malformed object path")
return APIError{
HTTPStatus: http.StatusBadRequest,
Err: fmt.Errorf("malformed object path"),
}
}
id := parts[2]

Expand All @@ -917,7 +923,10 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
expanded, ok := rawCfgIndex[id]
defer currentCfgMu.RUnlock()
if !ok {
return fmt.Errorf("unknown object ID '%s'", id)
return APIError{
HTTPStatus: http.StatusNotFound,
Err: fmt.Errorf("unknown object ID '%s'", id),
}
}

// piece the full URL path back together
Expand Down

0 comments on commit 07c7dc6

Please sign in to comment.