What should happen if you send an invalid or unexpected search parameter to a FHIR server?
That depends. What a FHIR server does in the face of unknown parameters can be controlled by the “prefer” request header.
- Prefer: handling=strict
The server returns an error if it finds any unknown or unsupported parameters. - Prefer: handling=lenient
The server ignores any unknown or unsupported parameters and runs the rest of the query. It may choose to add an OperationOutcome to the response Bundle with details.
You can force particular parameter handling by specifying one of the above “prefer” types in the request headers. Or you can leave out the header and live with whichever option the server is configured to support by default.
From the FHIR documentation:
In general, servers SHOULD ignore unknown or unsupported parameters.
The reason for this is that extra parameters may be added to the request query without the client realizing and this should not negatively impact the query.
What should a client app do?
It could add a “strict” request header. But then the query will fail if extra parameters are added further downstream.
It could add a “lenient” request header. But then any typos in the search parameters will not be caught.
There are a couple of steps you can take.
- Look for OperationOutcome resources in the response Bundle and pay attention to any warnings.
- Compare the search parameters in the Bundle.link self element against the parameters you sent. If they’re not the same, you may have a problem.
More about error handling in FHIR: https://www.hl7.org/fhir/r4/search.html#errors
---