Skip to content

Commit

Permalink
Handle null values in fhir-server-config and throw for exceptional case
Browse files Browse the repository at this point in the history
Previously, we'd through an IllegalStateException if we encountered a
null value. This came up because the helm `toJson` function produces all
possibly fields for an object, even when some are null.

If we have an invalid config (such as described above), in
FHIRRestHelper.validateResource we were swallowing the underlying
exception and instread constructing a generic OperationOutcomeIssue with
message "Error retrieving profile configuration". This was being handled
just like any other validation error and so, even though it was a server
config issue, this was not clear to the client.

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Oct 1, 2021
1 parent 70383a5 commit 2d82cc6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
10 changes: 6 additions & 4 deletions fhir-config/src/main/java/com/ibm/fhir/config/PropertyGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import java.util.List;
import java.util.Map;

import com.ibm.fhir.core.FHIRUtilities;

import jakarta.json.JsonArray;
import jakarta.json.JsonNumber;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;

import com.ibm.fhir.core.FHIRUtilities;

/**
* This class represents a collection of properties - a property group. This could be the entire set of properties
* resulting from loading the configuration, or it could be just a sub-structure within the overall config hierarchy, as
Expand Down Expand Up @@ -107,7 +107,7 @@ public String getStringProperty(String propertyName, String defaultValue) throws
/**
* This is a convenience function that will retrieve an array property, then convert it
* to a list of Strings by calling toString() on each array element.
*
*
* @param propertyName the name of the property to retrieve
* @return a List<String> containing the elements from the JSON array property; possibly null
* @throws Exception
Expand Down Expand Up @@ -262,7 +262,7 @@ public String toString() {
/**
* Converts the specified JsonValue into the appropriate java.lang.* type.
* @param jsonValue the JsonValue instance to be converted
* @return an instance of Boolean, Integer, String, PropertyGroup, or List<Object>
* @return either null or an instance of Boolean, Integer, String, PropertyGroup, or List<Object>
* @throws Exception
*/
public static Object convertJsonValue(JsonValue jsonValue) throws Exception {
Expand Down Expand Up @@ -292,6 +292,8 @@ public static Object convertJsonValue(JsonValue jsonValue) throws Exception {
case FALSE:
result = Boolean.FALSE;
break;
case NULL:
break;
default:
throw new IllegalStateException("Unexpected JSON value type: " + jsonValue.getValueType().name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ private List<FHIRRegistryResource> computeRegistryResources(Class<? extends Reso
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
} catch (Exception e) {
log.log(Level.WARNING, "An error occurred during a search interaction", e);
log.log(Level.WARNING, "An error occurred during the underlying search interaction; returning empty", e);
} finally {
if (transactionHelper != null) {
try {
transactionHelper.rollback();
} catch (FHIRPersistenceException e) {
log.log(Level.WARNING, "An error occurred ending the current transaction", e);
log.log(Level.WARNING, "An error occurred while rolling back the current transaction", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3279,8 +3279,7 @@ private List<Issue> validateResource(Resource resource) throws FHIRValidationExc
}
}
} catch (Exception e) {
return Collections.singletonList(buildOperationOutcomeIssue(IssueSeverity.ERROR, IssueType.UNKNOWN,
"Error retrieving profile configuration."));
throw new FHIRValidationException("Error retrieving profile configuration.", e);
}

// If required profiles were configured, perform validation of asserted profiles against required profiles
Expand Down

0 comments on commit 2d82cc6

Please sign in to comment.