Skip to content

Commit

Permalink
issue #2556 - add the entry index to the error message
Browse files Browse the repository at this point in the history
Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Sep 17, 2021
1 parent c2ff06d commit f6f9299
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1769,8 +1769,7 @@ private List<Entry> processEntriesByMethod(Bundle requestBundle, Map<Integer, En
}
} catch (FHIRPersistenceResourceNotFoundException e) {
if (failFast) {
String msg = "Error while processing request bundle.";
throw new FHIRRestBundledRequestException(msg, e).withIssue(e.getIssues());
updateIssuesWithEntryIndexAndThrow(entryIndex, e);
}

responseEntries[entryIndex] = Entry.builder()
Expand All @@ -1782,8 +1781,7 @@ private List<Entry> processEntriesByMethod(Bundle requestBundle, Map<Integer, En
logBundledRequestCompletedMsg(requestDescription.toString(), initialTime, SC_NOT_FOUND);
} catch (FHIRPersistenceResourceDeletedException e) {
if (failFast) {
String msg = "Error while processing request bundle.";
throw new FHIRRestBundledRequestException(msg, e).withIssue(e.getIssues());
updateIssuesWithEntryIndexAndThrow(entryIndex, e);
}

responseEntries[entryIndex] = Entry.builder()
Expand All @@ -1795,8 +1793,7 @@ private List<Entry> processEntriesByMethod(Bundle requestBundle, Map<Integer, En
logBundledRequestCompletedMsg(requestDescription.toString(), initialTime, SC_GONE);
} catch (FHIROperationException e) {
if (failFast) {
String msg = "Error while processing request bundle.";
throw new FHIRRestBundledRequestException(msg, e).withIssue(e.getIssues());
updateIssuesWithEntryIndexAndThrow(entryIndex, e);
}

Status status;
Expand Down Expand Up @@ -1841,6 +1838,16 @@ private List<Entry> processEntriesByMethod(Bundle requestBundle, Map<Integer, En
}
}

private void updateIssuesWithEntryIndexAndThrow(Integer entryIndex, FHIROperationException cause) throws FHIROperationException {
String msg = "Error while processing request bundle on entry " + entryIndex;
List<Issue> updatedIssues = cause.getIssues().stream()
.map(i -> i.toBuilder().expression(string("Bundle.entry[" + entryIndex + "]")).build())
.collect(Collectors.toList());
// no need to keep the issues in the cause any more since we've "promoted" them to the wrapped exception
cause.withIssue(Collections.emptyList());
throw new FHIRRestBundledRequestException(msg, cause).withIssue(updatedIssues);
}

/**
* Processes a request entry with a request method of Patch.
*
Expand Down

0 comments on commit f6f9299

Please sign in to comment.