Search in sources :

Example 41 with ErrorData

use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.

the class ExceptionMapperHelper method accepts.

public static boolean accepts(ErrorResponse errorResponse, int acceptedStatusCode, String metaTypeValue) {
    if (errorResponse.getHttpStatus() != acceptedStatusCode) {
        return false;
    }
    Iterator<ErrorData> errors = errorResponse.getErrors().iterator();
    if (!errors.hasNext()) {
        return false;
    }
    ErrorData error = errors.next();
    Map<String, Object> meta = error.getMeta();
    return meta != null && metaTypeValue.equals(meta.get(META_TYPE_KEY));
}
Also used : ErrorData(io.crnk.core.engine.document.ErrorData)

Example 42 with ErrorData

use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.

the class ErrorResponse method toResponse.

public Response toResponse() {
    Document responseDocument = new Document();
    List<ErrorData> errors = new ArrayList<>();
    for (ErrorData error : getErrors()) {
        errors.add(error);
    }
    responseDocument.setErrors(errors);
    return new Response(responseDocument, getHttpStatus());
}
Also used : JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Response(io.crnk.core.engine.dispatcher.Response) Document(io.crnk.core.engine.document.Document) ErrorData(io.crnk.core.engine.document.ErrorData)

Example 43 with ErrorData

use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.

the class DocumentMapperTest method testErrors.

@Test
public void testErrors() {
    JsonApiResponse response = new JsonApiResponse();
    ErrorData error = Mockito.mock(ErrorData.class);
    response.setErrors(Arrays.asList(error));
    Document document = mapper.toDocument(response, createAdapter(Task.class));
    List<ErrorData> errors = document.getErrors();
    Assert.assertEquals(1, errors.size());
    Assert.assertSame(error, errors.get(0));
}
Also used : LazyTask(io.crnk.core.mock.models.LazyTask) Task(io.crnk.core.mock.models.Task) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Document(io.crnk.core.engine.document.Document) ErrorData(io.crnk.core.engine.document.ErrorData) Test(org.junit.Test)

Example 44 with ErrorData

use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.

the class ErrorDataBuilderTest method shouldSetSourcePointer.

@Test
public void shouldSetSourcePointer() throws Exception {
    ErrorData error = ErrorData.builder().setSourcePointer(ErrorDataMother.POINTER).build();
    assertThat(error.getSourcePointer()).isEqualTo(ErrorDataMother.POINTER);
}
Also used : ErrorData(io.crnk.core.engine.document.ErrorData) Test(org.junit.Test)

Example 45 with ErrorData

use of io.crnk.core.engine.document.ErrorData in project crnk-framework by crnk-project.

the class ErrorDataBuilderTest method shouldSetMeta.

@Test
public void shouldSetMeta() throws Exception {
    ErrorData error = ErrorData.builder().setMeta(ErrorDataMother.META).build();
    assertThat(error.getMeta()).contains(MapEntry.entry(ErrorDataMother.META_KEY, ErrorDataMother.META_VALUE));
}
Also used : ErrorData(io.crnk.core.engine.document.ErrorData) Test(org.junit.Test)

Aggregations

ErrorData (io.crnk.core.engine.document.ErrorData)50 Test (org.junit.Test)30 ErrorResponse (io.crnk.core.engine.error.ErrorResponse)10 Document (io.crnk.core.engine.document.Document)9 ErrorDataBuilder (io.crnk.core.engine.document.ErrorDataBuilder)8 ExceptionMapperRegistry (io.crnk.core.engine.internal.exception.ExceptionMapperRegistry)6 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)6 ArrayList (java.util.ArrayList)5 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HttpAdapterResponse (io.crnk.client.http.HttpAdapterResponse)3 ExceptionMapper (io.crnk.core.engine.error.ExceptionMapper)3 BadRequestException (io.crnk.core.exception.BadRequestException)3 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)2 InternalServerErrorException (io.crnk.core.exception.InternalServerErrorException)2 ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)2 Optional (io.crnk.core.utils.Optional)2 HashMap (java.util.HashMap)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CrnkBoot (io.crnk.core.boot.CrnkBoot)1