This repository has been archived by the owner on Aug 9, 2023. It is now read-only.
Create a patchArrayDecorator
that automatically retries failed patch operations on null arrays
#200
Labels
Problem
The patch operation is very useful in allowing fine-grained updates in contexts where it makes.
One annoyance though is in the context of patching array attributes.
The problem is that arrays is FHIR are not supposed to be empty. In that case, the attribute should simply not be present.
By default, JSON Patching an element of an array fails if the array is null; in this case, you have to patch the whole array.
This leads to code like this:
It would be nice if we were able to just do this:
and have it work in all cases.
Suggested solution
Write a FHIR Client decorator that decorate the patch method, intercept errors on patch operations, and if there was an attempt to set a value inside an array (e.g. an
add
operation with the path ending in/{number or -}
, retries it with setting the whole attribute with an array value.If the retry is successful, return the retry result. If it is unsuccessful, return the original response or throw the original error.
If there are multiple patch operations pertaining to arrays, we don't retry anything as we don't know which is which.
Examples
Example interaction:
Rewrote patch
Error responses may vary from server to server; we may want to act on response status === 400 only, disregarding the actual
OperationOutcome
response.The text was updated successfully, but these errors were encountered: