Skip to content

Commit 440d4c8

Browse files
ibaisiibaisismile
andauthored
update conditional create/uodate error message (#7221)
* update conditional create/uodate error message * use actual conditional url in theIfNoneExist * revert systemRequestDetail mock * add changelog to conditional create/update error msg * fix conditional update tests --------- Co-authored-by: Ivan Baisi <[email protected]>
1 parent 99b1586 commit 440d4c8

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: add
3+
issue: 7215
4+
title: "Improve error message on conditional create/update to reference which resource is failing to be persisted.
5+
Resource url and type added to supplied resource."

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,18 @@ private void verifyMatchUrlForConditionalCreateOrUpdate(
851851
myInMemoryResourceMatcher.match(theIfNoneExist, theResource, theParams, theRequestDetails);
852852

853853
if (outcome.supported() && !outcome.matched()) {
854-
String errorMsg = getConditionalCreateOrUpdateErrorMsg(theCreateOrUpdate);
854+
String errorMsg =
855+
getConditionalCreateOrUpdateErrorMsg(theCreateOrUpdate, theIfNoneExist, theResource.fhirType());
855856
throw new InvalidRequestException(Msg.code(929) + errorMsg);
856857
}
857858
}
858859

859-
private String getConditionalCreateOrUpdateErrorMsg(CreateOrUpdateByMatch theCreateOrUpdate) {
860+
private String getConditionalCreateOrUpdateErrorMsg(
861+
CreateOrUpdateByMatch theCreateOrUpdate, String url, String resourceType) {
860862
return String.format(
861-
"Failed to process conditional %s. " + "The supplied resource did not satisfy the conditional URL.",
862-
theCreateOrUpdate.name().toLowerCase());
863+
"Failed to process conditional %s. "
864+
+ "The supplied resource %s of type %s did not satisfy the conditional URL.",
865+
theCreateOrUpdate.name().toLowerCase(), url, resourceType);
863866
}
864867

865868
@SuppressWarnings("unchecked")

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void testConditionalCreateFailsIfMatchUrlDoesntMatch() {
430430
myObservationDao.create(obs, "identifier=A%20B", newSrd());
431431
fail();
432432
} catch (InvalidRequestException e) {
433-
assertEquals(Msg.code(929) + "Failed to process conditional create. The supplied resource did not satisfy the conditional URL.", e.getMessage());
433+
assertEquals(Msg.code(929) + "Failed to process conditional create. The supplied resource identifier=A%20B of type Observation did not satisfy the conditional URL.", e.getMessage());
434434
}
435435
}
436436

@@ -455,7 +455,7 @@ public void testConditionalCreateFailsIfMatchUrlDoesntMatch_InTransaction() {
455455
mySystemDao.transaction(newSrd(), (Bundle) bb.getBundle());
456456
fail();
457457
} catch (InvalidRequestException e) {
458-
assertEquals(Msg.code(929) + "Failed to process conditional create. The supplied resource did not satisfy the conditional URL.", e.getMessage());
458+
assertEquals(Msg.code(929) + "Failed to process conditional create. The supplied resource identifier=A%20B of type Observation did not satisfy the conditional URL.", e.getMessage());
459459
}
460460
}
461461

@@ -466,7 +466,7 @@ public void testConditionalCreateFailsIfMatchUrlCaseIsDifferent() {
466466
assertThatThrownBy(() -> myObservationDao.create(obs, "identifier=xxx", newSrd()))
467467
.isInstanceOf(InvalidRequestException.class)
468468
.hasMessage(Msg.code(929) +
469-
"Failed to process conditional create. The supplied resource did not satisfy the conditional URL.");
469+
"Failed to process conditional create. The supplied resource identifier=xxx of type Observation did not satisfy the conditional URL.");
470470
}
471471

472472
@Test

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void withPreventInvalidatingConditionalMatchCriteria_true_mustThrow() {
206206
InvalidRequestException thrown = assertThrows(InvalidRequestException.class,
207207
() -> myPatientDao.update(p2,
208208
"Patient?identifier=http://kookaburra.text/id|kookaburra2", mySrd));
209-
assertThat(thrown.getMessage()).endsWith("Failed to process conditional create. The supplied resource did not satisfy the conditional URL.");
209+
assertThat(thrown.getMessage()).endsWith("Failed to process conditional create. The supplied resource Patient?identifier=http://kookaburra.text/id|kookaburra2 of type Patient did not satisfy the conditional URL.");
210210
}
211211

212212
@Test
@@ -220,7 +220,7 @@ public void withPreventInvalidatingConditionalMatchCriteria_false_mustThrow() {
220220
InvalidRequestException thrown = assertThrows(InvalidRequestException.class,
221221
() -> myPatientDao.update(p2,
222222
"Patient?identifier=http://kookaburra.text/id|kookaburra2", mySrd));
223-
assertThat(thrown.getMessage()).endsWith("Failed to process conditional create. The supplied resource did not satisfy the conditional URL.");
223+
assertThat(thrown.getMessage()).endsWith("Failed to process conditional create. The supplied resource Patient?identifier=http://kookaburra.text/id|kookaburra2 of type Patient did not satisfy the conditional URL.");
224224
}
225225

226226
}
@@ -251,7 +251,7 @@ public void withPreventInvalidatingConditionalMatchCriteria_true_mustThrow() {
251251
InvalidRequestException thrown = assertThrows(InvalidRequestException.class,
252252
() -> myPatientDao.update(p2,
253253
"Patient?identifier=http://kookaburra.text/id|kookaburra1", mySrd));
254-
assertThat(thrown.getMessage()).endsWith("Failed to process conditional update. The supplied resource did not satisfy the conditional URL.");
254+
assertThat(thrown.getMessage()).endsWith("Failed to process conditional update. The supplied resource Patient?identifier=http://kookaburra.text/id|kookaburra1 of type Patient did not satisfy the conditional URL.");
255255
}
256256
}
257257
}

0 commit comments

Comments
 (0)