Merge pull request #2497 from hapifhir/issue-2496-incorrect-error-on-custom-sp

Fix bug with inconsistent error messages
This commit is contained in:
Tadgh 2021-03-24 10:09:40 -04:00 committed by GitHub
commit 0aadcbdae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 0 deletions

View File

@ -277,6 +277,8 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
}
}
@Test
@Disabled
public void testCreateInvalidParamInvalidResourceName() {

View File

@ -14,6 +14,7 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.gclient.ReferenceClientParam;
import ca.uhn.fhir.rest.gclient.StringClientParam;
import ca.uhn.fhir.rest.gclient.TokenClientParam;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.util.BundleUtil;
@ -31,6 +32,7 @@ import org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResource
import org.hl7.fhir.r4.model.CodeType;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.r4.model.ExplanationOfBenefit;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Observation.ObservationStatus;
import org.hl7.fhir.r4.model.Patient;
@ -54,6 +56,8 @@ import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@ -416,6 +420,59 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide
}
@SuppressWarnings("unused")
@Test
public void testSearchWithCustomParamInvalidDateFormat() {
SearchParameter dateParameter = new SearchParameter();
dateParameter.setId("explanationofbenefit-service-date");
dateParameter.setName("ExplanationOfBenefit_ServiceDate");
dateParameter.setCode("service-date");
dateParameter.setDescription("test");
dateParameter.setUrl("http://integer");
dateParameter.setStatus(Enumerations.PublicationStatus.ACTIVE);
dateParameter.addBase("ExplanationOfBenefit");
dateParameter.setType(Enumerations.SearchParamType.DATE);
dateParameter.setExpression("ExplanationOfBenefit.billablePeriod | ExplanationOfBenefit.item.serviced as Date | ExplanationOfBenefit.item.serviced as Period");
dateParameter.setXpath("f:ExplanationOfBenefit/f:billablePeriod | f:ExplanationOfBenefit/f:item/f:serviced/f:servicedDate | f:ExplanationOfBenefit/f:item/f:serviced/f:servicedPeriod");
dateParameter.setXpathUsage(SearchParameter.XPathUsageType.NORMAL);
mySearchParameterDao.update(dateParameter);
mySearchParamRegistry.forceRefresh();
IBundleProvider results;
List<String> foundResources;
Bundle result;
//Try with builtin SP
try {
myClient
.search()
.forResource(ExplanationOfBenefit.class)
.where(new StringClientParam("created").matches().value("01-01-2020"))
.returnBundle(Bundle.class)
.execute();
} catch (Exception e) {
assertThat(e.getMessage(), is(equalTo("HTTP 400 Bad Request: Invalid date/time format: \"01-01-2020\"")));
}
//Now with custom SP
try {
myClient
.search()
.forResource(ExplanationOfBenefit.class)
.where(new StringClientParam("service-date").matches().value("01-01-2020"))
.returnBundle(Bundle.class)
.execute();
} catch (Exception e) {
assertThat(e.getMessage(), is(equalTo("HTTP 400 Bad Request: Invalid date/time format: \"01-01-2020\"")));
}
}
/**
* See #1300
*/

View File

@ -26,6 +26,7 @@ import ca.uhn.fhir.interceptor.api.HookParams;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
@ -251,6 +252,9 @@ public abstract class BaseMethodBinding<T> {
if (e.getCause() instanceof BaseServerResponseException) {
throw (BaseServerResponseException) e.getCause();
}
if (e.getTargetException() instanceof DataFormatException) {
throw (DataFormatException)e.getTargetException();
}
throw new InternalErrorException("Failed to call access method: " + e.getCause(), e);
} catch (Exception e) {
throw new InternalErrorException("Failed to call access method: " + e.getCause(), e);