From 4ebf92d02be740ca0f05d70196b9ea25031d2c39 Mon Sep 17 00:00:00 2001 From: Tuncay Namli Date: Fri, 24 Jan 2025 16:23:29 +0300 Subject: [PATCH] :bugs: fix: Fix the Http error status for conditional update case i.e. No matches, id provided and already exist from 400 to 409 --- .../io/onfhir/api/service/FHIRUpdateService.scala | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/onfhir-core/src/main/scala/io/onfhir/api/service/FHIRUpdateService.scala b/onfhir-core/src/main/scala/io/onfhir/api/service/FHIRUpdateService.scala index 51b5579c..0eaae759 100644 --- a/onfhir-core/src/main/scala/io/onfhir/api/service/FHIRUpdateService.scala +++ b/onfhir-core/src/main/scala/io/onfhir/api/service/FHIRUpdateService.scala @@ -8,9 +8,8 @@ import io.onfhir.config.FhirConfigurationManager.fhirConfig import io.onfhir.api.util.FHIRUtil import io.onfhir.api.validation.FHIRApiValidator import io.onfhir.authz.AuthzContext - import io.onfhir.db.{ResourceManager, TransactionSession} -import io.onfhir.exception.{BadRequestException, PreconditionFailedException} +import io.onfhir.exception.{BadRequestException, ConflictException, PreconditionFailedException} import scala.concurrent.Future import scala.util.Try @@ -127,17 +126,17 @@ class FHIRUpdateService(transactionSession: Option[TransactionSession] = None) e if(FHIRUtil.isDeleted(foundResource)) { val oldVersion = FHIRUtil.extractVersionFromResource(foundResource) performUpdate(resource, _type, Some(rid), prefer, testUpdate, Some(oldVersion -> foundResource), wasDeleted = true) - }else { //Otherwise it is problematic - logger.debug("Supplied resource id matches another FHIR resource which does not satisfy the given query!") - throw new BadRequestException(Seq( + } else { //Otherwise it is problematic + logger.debug("Resource already exists with given id but does not satisfy the given query!") + throw new ConflictException( OutcomeIssue( FHIRResponse.SEVERITY_CODES.ERROR, FHIRResponse.OUTCOME_CODES.INVALID, None, - Some(s"Supplied resource id matches another FHIR resource which does not satisfy the given query!"), + Some(s"Resource already exists with given id but does not satisfy the given queryy!"), Nil ) - )) + ) } } }