Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 21:45 UTC
admin: Write proper status on invalid requests (#4569) (fix #4561)
Alok Naushad committed
Feb 12, 2022 at 01:53 UTC
32aad909380f08a40389a33bfe788c8a35b1d850
1 file changed
+12
-3
admin.go
+12
-3
@@ -924,10 +924,16 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
924
925
parts := strings.Split(idPath, "/")
926
if len(parts) < 3 || parts[2] == "" {
927
- return fmt.Errorf("request path is missing object ID")
927
+ return APIError{
928
+ HTTPStatus: http.StatusBadRequest,
929
+ Err: fmt.Errorf("request path is missing object ID"),
930
+ }
931
}
932
if parts[0] != "" || parts[1] != "id" {
930
- return fmt.Errorf("malformed object path")
933
+ return APIError{
934
+ HTTPStatus: http.StatusBadRequest,
935
+ Err: fmt.Errorf("malformed object path"),
936
+ }
937
}
938
id := parts[2]
939
@@ -936,7 +942,10 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
942
expanded, ok := rawCfgIndex[id]
943
defer currentCfgMu.RUnlock()
944
if !ok {
939
- return fmt.Errorf("unknown object ID '%s'", id)
945
+ return APIError{
946
+ HTTPStatus: http.StatusNotFound,
947
+ Err: fmt.Errorf("unknown object ID '%s'", id),
948
+ }
949
}
950
951
// piece the full URL path back together