mirror of https://github.com/hashicorp/consul
agent: prevent duplicate error messages for maintenance api
parent
7d663aa1ed
commit
61d17e65f5
|
@ -224,14 +224,17 @@ func (s *HTTPServer) AgentServiceMaintenance(resp http.ResponseWriter, req *http
|
||||||
if err = s.agent.EnableServiceMaintenance(serviceID, reason); err != nil {
|
if err = s.agent.EnableServiceMaintenance(serviceID, reason); err != nil {
|
||||||
resp.WriteHeader(404)
|
resp.WriteHeader(404)
|
||||||
resp.Write([]byte(err.Error()))
|
resp.Write([]byte(err.Error()))
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = s.agent.DisableServiceMaintenance(serviceID); err != nil {
|
if err = s.agent.DisableServiceMaintenance(serviceID); err != nil {
|
||||||
resp.WriteHeader(404)
|
resp.WriteHeader(404)
|
||||||
resp.Write([]byte(err.Error()))
|
resp.Write([]byte(err.Error()))
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, err
|
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) AgentNodeMaintenance(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) AgentNodeMaintenance(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
|
|
@ -542,9 +542,6 @@ func TestHTTPAgent_ServiceMaintenanceEndpoint_BadRequest(t *testing.T) {
|
||||||
// Fails when bad service ID provided
|
// Fails when bad service ID provided
|
||||||
req, _ = http.NewRequest("PUT", "/v1/agent/service/maintenance/_nope_?enable=true", nil)
|
req, _ = http.NewRequest("PUT", "/v1/agent/service/maintenance/_nope_?enable=true", nil)
|
||||||
resp = httptest.NewRecorder()
|
resp = httptest.NewRecorder()
|
||||||
if _, err := srv.AgentServiceMaintenance(resp, req); err == nil {
|
|
||||||
t.Fatalf("should have errored")
|
|
||||||
}
|
|
||||||
if resp.Code != 404 {
|
if resp.Code != 404 {
|
||||||
t.Fatalf("expected 404, got %d", resp.Code)
|
t.Fatalf("expected 404, got %d", resp.Code)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue