use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class OptimisticLockExceptionMapper method toErrorResponse.
@Override
public ErrorResponse toErrorResponse(OptimisticLockException cve) {
HashMap<String, Object> meta = new HashMap<>();
meta.put(META_TYPE_KEY, JPA_OPTIMISTIC_LOCK_EXCEPTION_TYPE);
ErrorData error = ErrorData.builder().setMeta(meta).setCode(ERROR_TYPE).setStatus(Integer.toString(HttpStatus.CONFLICT_409)).setDetail(cve.getMessage()).build();
return ErrorResponse.builder().setStatus(HttpStatus.CONFLICT_409).setSingleErrorData(error).build();
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class OptimisticLockExceptionMapper method fromErrorResponse.
@Override
public OptimisticLockException fromErrorResponse(ErrorResponse errorResponse) {
Iterable<ErrorData> errors = errorResponse.getErrors();
ErrorData error = errors.iterator().next();
String msg = error.getDetail();
return new OptimisticLockException(msg);
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class JpaExceptionMapperTests method testPersistenceException.
@Test
public void testPersistenceException() {
PersistenceException exception = new PersistenceException(new BadRequestException("test"));
ExceptionMapperRegistry exceptionMapperRegistry = boot.getExceptionMapperRegistry();
PersistenceExceptionMapper mapper = (PersistenceExceptionMapper) exceptionMapperRegistry.findMapperFor(PersistenceException.class).get();
ErrorResponse response = mapper.toErrorResponse(exception);
ErrorData errorData = response.getErrors().iterator().next();
Assert.assertEquals(Integer.toString(HttpStatus.BAD_REQUEST_400), errorData.getStatus());
Assert.assertEquals("test", errorData.getDetail());
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class JpaExceptionMapperTests method testPersistenceRollbackException.
@Test
public void testPersistenceRollbackException() {
javax.persistence.RollbackException exception = new javax.persistence.RollbackException(new BadRequestException("test"));
ExceptionMapperRegistry exceptionMapperRegistry = boot.getExceptionMapperRegistry();
PersistenceRollbackExceptionMapper mapper = (PersistenceRollbackExceptionMapper) exceptionMapperRegistry.findMapperFor(javax.persistence.RollbackException.class).get();
ErrorResponse response = mapper.toErrorResponse(exception);
ErrorData errorData = response.getErrors().iterator().next();
Assert.assertEquals(Integer.toString(HttpStatus.BAD_REQUEST_400), errorData.getStatus());
Assert.assertEquals("test", errorData.getDetail());
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class DocumentMapper method addErrors.
private void addErrors(Document doc, Iterable<ErrorData> errors) {
if (errors != null) {
List<ErrorData> errorList = new ArrayList<>();
for (ErrorData error : errors) {
errorList.add(error);
}
doc.setErrors(errorList);
}
}
Aggregations