From 1e5183fb89e1c7dd3c41da9e7e75ad170ae9bf81 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 20 Feb 2017 20:10:21 -0800 Subject: [PATCH] Deregistering non-existant job returns 404 Fixes https://github.com/hashicorp/nomad/issues/2326 --- command/agent/job_endpoint.go | 6 +++++- nomad/job_endpoint.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index be5071f74..ff9f08698 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -327,7 +327,11 @@ func (s *HTTPServer) jobDelete(resp http.ResponseWriter, req *http.Request, s.parseRegion(req, &args.Region) var out structs.JobDeregisterResponse - if err := s.agent.RPC("Job.Deregister", &args, &out); err != nil { + err := s.agent.RPC("Job.Deregister", &args, &out) + if err != nil { + if strings.HasSuffix(err.Error(), "does not exist") { + return nil, CodedError(404, err.Error()) + } return nil, err } setIndex(resp, out.Index) diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index bbed6b745..c43afc6d5 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -389,6 +389,10 @@ func (j *Job) Deregister(args *structs.JobDeregisterRequest, reply *structs.JobD return err } + if job == nil { + return fmt.Errorf("job %q does not exist", args.JobID) + } + // Commit this update via Raft _, index, err := j.srv.raftApply(structs.JobDeregisterRequestType, args) if err != nil {