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);
}
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();
}
Aggregations