Search in sources :

Example 16 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseResourceNotFoundExceptionIBMFormat.

@Test
public void testToResponseResourceNotFoundExceptionIBMFormat() throws Exception {
    JSONObject details = new JSONObject();
    details.put("text", "Resource 'Patient/patientId' not found.");
    JSONObject issue = new JSONObject();
    issue.put("severity", "fatal");
    issue.put("code", "not-found");
    issue.put("details", details);
    JSONArray issues = new JSONArray();
    issues.add(issue);
    JSONObject json = new JSONObject();
    json.put("resourceType", "OperationOutcome");
    json.put("id", "my-id");
    json.put("issue", issues);
    OperationOutcome outcome = parser.parseResource(OperationOutcome.class, json.toString());
    ResourceNotFoundException ex = new ResourceNotFoundException("Error", outcome);
    ex.setResponseBody(json.toString());
    Response response = new CohortServiceExceptionMapper().toResponse(ex);
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(400);
    expected.getErrors().add(newServiceError(404, "FHIR Resource Not Found: Error", "{\"issue\":[{\"severity\":\"fatal\",\"code\":\"not-found\",\"details\":{\"text\":\"Resource 'Patient\\/patientId' not found.\"}}],\"id\":\"my-id\",\"resourceType\":\"OperationOutcome\"}"));
    expected.setErrorSource(ErrorSource.FHIR_SERVER);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(net.minidev.json.JSONObject) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) JSONArray(net.minidev.json.JSONArray) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) Test(org.junit.Test)

Example 17 with ServiceErrorList

use of com.ibm.cohort.engine.api.service.model.ServiceErrorList in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapper method toResponse.

@Override
public Response toResponse(Throwable ex) {
    ServiceErrorList serviceErrorList = toServiceErrorList(ex);
    ResponseBuilder rb = Response.status(serviceErrorList.getStatusCode()).entity(serviceErrorList).type(MediaType.APPLICATION_JSON);
    return rb.build();
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList)

Aggregations

ServiceErrorList (com.ibm.cohort.engine.api.service.model.ServiceErrorList)17 Response (javax.ws.rs.core.Response)15 Test (org.junit.Test)15 FhirClientConnectionException (ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException)7 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)4 AuthenticationException (ca.uhn.fhir.rest.server.exceptions.AuthenticationException)2 ConnectException (java.net.ConnectException)2 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)2 CqlException (org.opencds.cqf.cql.engine.exception.CqlException)2 BaseServerResponseException (ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 MismatchedInputException (com.fasterxml.jackson.databind.exc.MismatchedInputException)1 ErrorSource (com.ibm.cohort.engine.api.service.model.ServiceErrorList.ErrorSource)1 ServiceError (com.ibm.watson.service.base.model.ServiceError)1 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)1 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 Status (javax.ws.rs.core.Response.Status)1