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 {