From f338236fe265b85c2a122b3b6491ecac45824802 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Wed, 10 Jun 2026 08:19:08 +0000 Subject: [PATCH] internal/rest/resources/cluster: Return 4XX errors on client input errors clusterMemberDelete is returning a SmartError when the given member is absent from the truststore. This makes it difficult for callers to distinguish "not found" from a real internal error. Switch to NotFound error, so callers can use IsNotFoundError to treat an already-absent member as a success. Additionally switched other client-related errors into BadRequest. (cherry picked from commit b1b192d1a61bea5699fac9e12ca4005088c073fd) Signed-off-by: Claudiu Belu --- internal/rest/resources/cluster.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/rest/resources/cluster.go b/internal/rest/resources/cluster.go index 6905982e..0550679d 100644 --- a/internal/rest/resources/cluster.go +++ b/internal/rest/resources/cluster.go @@ -415,13 +415,13 @@ func clusterMemberDelete(s state.State, r *http.Request) response.Response { force := r.URL.Query().Get("force") == "1" name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { - return response.SmartError(err) + return response.BadRequest(err) } allRemotes := s.Remotes().RemotesByName() remote, ok := allRemotes[name] if !ok { - return response.SmartError(fmt.Errorf("No remote exists with the given name %q", name)) + return response.NotFound(fmt.Errorf("No remote exists with the given name %q", name)) } ctx, cancel := context.WithTimeout(r.Context(), time.Second*60) @@ -533,11 +533,11 @@ func clusterMemberDelete(s state.State, r *http.Request) response.Response { } if len(clusterMembers)-numPending < 1 { - return response.SmartError(fmt.Errorf("Cannot remove cluster members, there are no remaining non-pending members")) + return response.BadRequest(fmt.Errorf("Cannot remove cluster members, there are no remaining non-pending members")) } if len(info) < 2 { - return response.SmartError(fmt.Errorf("Cannot leave a cluster with %d members", len(info))) + return response.BadRequest(fmt.Errorf("Cannot leave a cluster with %d members", len(info))) } // If we are removing the leader of a 2-node cluster, ensure the remaining node is a voter.