aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlok Naushad <[email protected]>2022-02-12 01:53:45 +0530
committerMatthew Holt <[email protected]>2022-02-15 12:13:33 -0700
commit32aad909380f08a40389a33bfe788c8a35b1d850 (patch)
tree52c990ab7925f9353be591887a9c43239b5be478
parent40b54434f3cdb804ef10eee0ba5d8d6c390e93d4 (diff)
downloadcaddy-32aad909380f08a40389a33bfe788c8a35b1d850.tar.gz
caddy-32aad909380f08a40389a33bfe788c8a35b1d850.zip
admin: Write proper status on invalid requests (#4569) (fix #4561)
-rw-r--r--admin.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/admin.go b/admin.go
index 157ae95f8..33bb5c6ef 100644
--- a/admin.go
+++ b/admin.go
@@ -924,10 +924,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]
@@ -936,7 +942,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