Search in sources :

Example 16 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class ConstraintValidationExceptionMapper method buildErrorList.

private ErrorResponse buildErrorList(ConstraintViolationException cve) {
    ErrorResponse response = new ErrorResponse();
    for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
        String detail = violation.getMessage();
        Object invalidValue = violation.getInvalidValue();
        if (invalidValue != null) {
            detail += "\n" + invalidValue;
        }
        Error error = new Error().code(violation.getPropertyPath().toString()).message(detail);
        response.addErrorsItem(error);
    }
    return response;
}
Also used : Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse)

Example 17 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class AbstractExceptionMapper method convert.

protected ErrorResponse convert(final int status, final String message, final String code, final Map<String, String> parameters) {
    final Error error = new Error();
    error.setStatus(String.valueOf(status));
    error.message(message);
    error.code("errors." + code);
    error.parameters(parameters);
    ErrorResponse response = new ErrorResponse();
    response.addErrorsItem(error);
    return response;
}
Also used : Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse)

Example 18 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class PageResourceTest method shouldNotGetPageContent.

@Test
public void shouldNotGetPageContent() {
    final Response response = target(UNKNOWN_PAGE).path("content").request().get();
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.page.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Page [" + UNKNOWN_PAGE + "] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 19 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class PageResourceTest method shouldNotGetPage.

@Test
public void shouldNotGetPage() {
    final Response response = target(UNKNOWN_PAGE).request().get();
    assertEquals(NOT_FOUND_404, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertNotNull(error);
    assertEquals("errors.page.notFound", error.getCode());
    assertEquals("404", error.getStatus());
    assertEquals("Page [" + UNKNOWN_PAGE + "] can not be found.", error.getMessage());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Test(org.junit.Test)

Example 20 with Error

use of io.gravitee.rest.api.portal.rest.model.Error in project gravitee-management-rest-api by gravitee-io.

the class ApplicationMetadataResourceTest method shouldNotGetMetadata.

@Test
public void shouldNotGetMetadata() {
    final Response response = target(APPLICATION).path("metadata").queryParam("page", 10).queryParam("size", 1).request().get();
    assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    List<Error> errors = errorResponse.getErrors();
    assertNotNull(errors);
    assertEquals(1, errors.size());
    Error error = errors.get(0);
    assertEquals("errors.pagination.invalid", error.getCode());
    assertEquals("400", error.getStatus());
    assertEquals("Pagination is not valid", error.getMessage());
}
Also used : Response(javax.ws.rs.core.Response) Error(io.gravitee.rest.api.portal.rest.model.Error) Test(org.junit.Test)

Aggregations

Error (io.gravitee.rest.api.portal.rest.model.Error)41 Response (javax.ws.rs.core.Response)39 Test (org.junit.Test)39 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)24 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)11 IOException (java.io.IOException)5 Collections.emptySet (java.util.Collections.emptySet)5 Collections.singletonList (java.util.Collections.singletonList)5 Before (org.junit.Before)5 Mockito.doReturn (org.mockito.Mockito.doReturn)5 HashSet (java.util.HashSet)4 NOT_FOUND_404 (io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404)3 OK_200 (io.gravitee.common.http.HttpStatusCode.OK_200)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Set (java.util.Set)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 ArgumentMatchers (org.mockito.ArgumentMatchers)3 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)2