Merge pull request #2339 from hashicorp/b-job-delete

Deregistering non-existant job returns 404
This commit is contained in:
Alex Dadgar 2017-02-20 20:11:24 -08:00 committed by GitHub
commit 084b63e711
2 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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 {