Mercurial > hg > orthanc
diff Core/JobsEngine/JobsRegistry.cpp @ 3240:e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 Feb 2019 17:26:45 +0100 |
parents | 20826867141f |
children | fe73717105b6 |
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp Fri Feb 15 16:38:12 2019 +0100 +++ b/Core/JobsEngine/JobsRegistry.cpp Fri Feb 15 17:26:45 2019 +0100 @@ -110,7 +110,7 @@ job->GetJobType(jobType_); job->Start(); - lastStatus_ = JobStatus(ErrorCode_Success, *job_); + lastStatus_ = JobStatus(ErrorCode_Success, "", *job_); } const std::string& GetId() const @@ -318,7 +318,7 @@ job_->GetJobType(jobType_); job_->Start(); - lastStatus_ = JobStatus(ErrorCode_Success, *job_); + lastStatus_ = JobStatus(ErrorCode_Success, "", *job_); } }; @@ -739,7 +739,7 @@ } - bool JobsRegistry::SubmitAndWait(Json::Value& successContent, + void JobsRegistry::SubmitAndWait(Json::Value& successContent, IJob* job, // Takes ownership int priority) { @@ -764,7 +764,25 @@ else if (state == JobState_Failure) { // Failure - break; + JobsIndex::const_iterator it = jobsIndex_.find(id); + if (it != jobsIndex_.end()) // Should always be true, already tested in GetStateInternal() + { + ErrorCode code = it->second->GetLastStatus().GetErrorCode(); + const std::string& details = it->second->GetLastStatus().GetDetails(); + + if (details.empty()) + { + throw OrthancException(code); + } + else + { + throw OrthancException(code, details); + } + } + else + { + throw OrthancException(ErrorCode_InternalError); + } } else if (state == JobState_Success) { @@ -781,7 +799,7 @@ successContent = status.GetPublicContent(); } - break; + return; } else { @@ -790,8 +808,6 @@ } } } - - return (state == JobState_Success); } @@ -1320,7 +1336,8 @@ } - void JobsRegistry::RunningJob::UpdateStatus(ErrorCode code) + void JobsRegistry::RunningJob::UpdateStatus(ErrorCode code, + const std::string& details) { if (!IsValid()) { @@ -1328,7 +1345,7 @@ } else { - JobStatus status(code, *job_); + JobStatus status(code, details, *job_); boost::mutex::scoped_lock lock(registry_.mutex_); registry_.CheckInvariants();