use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class ConnectedOperations method createDatasetExpectError.
public ErrorModel createDatasetExpectError(DatasetRequestModel datasetRequest, HttpStatus expectedStatus) throws Exception {
MvcResult result = mvc.perform(post("/api/repository/v1/datasets").contentType(MediaType.APPLICATION_JSON).content(TestUtils.mapToJson(datasetRequest))).andReturn();
MockHttpServletResponse response = validateJobModelAndWait(result);
ErrorModel errorModel = handleFailureCase(response, expectedStatus);
return errorModel;
}
use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class ConnectedOperations method checkDeleteResponse.
public void checkDeleteResponse(MockHttpServletResponse response) throws Exception {
HttpStatus status = HttpStatus.valueOf(response.getStatus());
if (status.is2xxSuccessful()) {
DeleteResponseModel responseModel = TestUtils.mapFromJson(response.getContentAsString(), DeleteResponseModel.class);
assertTrue("Valid delete response object state enumeration", (responseModel.getObjectState() == DeleteResponseModel.ObjectStateEnum.DELETED || responseModel.getObjectState() == DeleteResponseModel.ObjectStateEnum.NOT_FOUND));
} else {
ErrorModel errorModel = handleFailureCase(response, HttpStatus.NOT_FOUND);
assertNotNull("error model returned", errorModel);
}
}
use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.
the class ApiValidationExceptionHandler method handleMethodArgumentNotValid.
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
BindingResult bindingResult = ex.getBindingResult();
List<String> errorDetails = bindingResult.getFieldErrors().stream().map(this::formatFieldError).collect(toList());
ErrorModel errorModel = new ErrorModel().message("Validation errors - see error details").errorDetail(errorDetails);
return new ResponseEntity<>(errorModel, HttpStatus.BAD_REQUEST);
}
Aggregations