use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class ErrorDataBuilderTest method shouldSetStatus.
@Test
public void shouldSetStatus() throws Exception {
ErrorData error = ErrorData.builder().setStatus(ErrorDataMother.STATUS).build();
assertThat(error.getStatus()).isEqualTo(ErrorDataMother.STATUS);
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class AbstractWrappedExceptionMapper method toErrorResponse.
@Override
public ErrorResponse toErrorResponse(E exception) {
Throwable cause = exception.getCause();
if (cause != null) {
Optional<JsonApiExceptionMapper> mapper = context.getExceptionMapperRegistry().findMapperFor(cause.getClass());
if (mapper.isPresent()) {
return mapper.get().toErrorResponse(cause);
}
}
LOGGER.error("failed to process request due to jpa exception", exception);
// no mapper found, return default error
int status = getStatus();
ErrorData errorData = ErrorData.builder().setStatus(Integer.toString(status)).setTitle(exception.getMessage()).build();
return ErrorResponse.builder().setSingleErrorData(errorData).setStatus(status).build();
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class HibernateConstraintViolationExceptionMapper method accepts.
@Override
public boolean accepts(ErrorResponse errorResponse) {
if (errorResponse.getHttpStatus() != HttpStatus.UNPROCESSABLE_ENTITY_422) {
return false;
}
Iterable<ErrorData> errors = errorResponse.getErrors();
Iterator<ErrorData> iterator = errors.iterator();
if (!iterator.hasNext())
return false;
ErrorData errorData = iterator.next();
Map<String, Object> meta = errorData.getMeta();
return meta != null && HIBERNATE_CONSTRAINT_VIOLATION_EXCEPTION.equals(meta.get(META_TYPE_KEY));
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class BraveResponseFilterTest method statusCodeNotOkWhenEmptyErrors.
@Test
public void statusCodeNotOkWhenEmptyErrors() {
ErrorData errorData = new ErrorDataBuilder().setId("test").build();
JsonApiResponse response = new JsonApiResponse();
response.setErrors(Arrays.asList(errorData));
Mockito.when(filterChain.doFilter(Mockito.any(RepositoryFilterContext.class))).thenReturn(response);
filter.filterRequest(filterContext, filterChain);
Mockito.verify(span, Mockito.times(1)).tag(BraveRepositoryFilter.STATUS_CODE_ANNOTATION, BraveRepositoryFilter.STRING_EXCEPTION);
}
use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.
the class BraveResponseFilterTest method statusCodeOkWhenEmptyErrors.
@Test
public void statusCodeOkWhenEmptyErrors() {
JsonApiResponse response = new JsonApiResponse();
response.setErrors(new ArrayList<ErrorData>());
Mockito.when(filterChain.doFilter(Mockito.any(RepositoryFilterContext.class))).thenReturn(response);
filter.filterRequest(filterContext, filterChain);
Mockito.verify(span, Mockito.times(1)).tag(BraveRepositoryFilter.STATUS_CODE_ANNOTATION, BraveRepositoryFilter.STRING_OK);
}
Aggregations