Search in sources :

Example 1 with ErrorResponse

use of com.redhat.service.bridge.infra.api.models.responses.ErrorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class InternalPlatformExceptionMapper method toResponse.

@Override
public Response toResponse(InternalPlatformException e) {
    LOGGER.warn("Internal Platform exception", e);
    // InternalPlatformException is always returned.
    Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
    ErrorResponse errorResponse = ErrorResponse.from(internalPlatformExceptionBridgeError);
    errorResponse.setReason(String.format(MESSAGE_TEMPLATE, e.getClass().getName(), e.getMessage()));
    builder.entity(errorResponse);
    return builder.build();
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(com.redhat.service.bridge.infra.api.models.responses.ErrorResponse) ErrorResponse(com.redhat.service.bridge.infra.api.models.responses.ErrorResponse)

Example 2 with ErrorResponse

use of com.redhat.service.bridge.infra.api.models.responses.ErrorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesAPITest method getUnexistingBridge.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void getUnexistingBridge() {
    ErrorResponse response = TestUtils.getBridge("not-the-id").then().statusCode(404).extract().as(ErrorResponse.class);
    assertThat(response.getId()).isEqualTo("4");
    assertThat(response.getCode()).endsWith("4");
    assertThat(response.getReason()).isNotBlank();
}
Also used : ErrorResponse(com.redhat.service.bridge.infra.api.models.responses.ErrorResponse) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with ErrorResponse

use of com.redhat.service.bridge.infra.api.models.responses.ErrorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ErrorsAPITest method testGetList.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
void testGetList() {
    ErrorListResponse response = given().contentType(ContentType.JSON).when().get(APIConstants.ERROR_API_BASE_PATH).as(ErrorListResponse.class);
    assertThat(exceptionClasses).hasSize((int) response.getTotal());
    assertThat(response.getItems().isEmpty()).isFalse();
    for (ErrorResponse item : response.getItems()) {
        assertThat(item).isEqualTo(given().contentType(ContentType.JSON).when().get(item.getHref()).as(ErrorResponse.class));
    }
}
Also used : ErrorListResponse(com.redhat.service.bridge.infra.api.models.responses.ErrorListResponse) ErrorResponse(com.redhat.service.bridge.infra.api.models.responses.ErrorResponse) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with ErrorResponse

use of com.redhat.service.bridge.infra.api.models.responses.ErrorResponse in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExternalUserExceptionMapper method toResponse.

@Override
public Response toResponse(ExternalUserException e) {
    LOGGER.debug("Failure", e);
    Optional<BridgeError> error = bridgeErrorService.getError(e);
    ResponseBuilder builder = Response.status(e.getStatusCode());
    if (error.isPresent()) {
        ErrorResponse errorResponse = ErrorResponse.from(error.get());
        errorResponse.setReason(e.getMessage());
        builder.entity(errorResponse);
    } else {
        LOGGER.warn("Information for exception type {} cannot be found", e.getClass());
        builder.entity(e.getMessage());
    }
    return builder.build();
}
Also used : BridgeError(com.redhat.service.bridge.infra.exceptions.BridgeError) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ErrorResponse(com.redhat.service.bridge.infra.api.models.responses.ErrorResponse)

Aggregations

ErrorResponse (com.redhat.service.bridge.infra.api.models.responses.ErrorResponse)4 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 TestSecurity (io.quarkus.test.security.TestSecurity)2 Test (org.junit.jupiter.api.Test)2 ErrorListResponse (com.redhat.service.bridge.infra.api.models.responses.ErrorListResponse)1 BridgeError (com.redhat.service.bridge.infra.exceptions.BridgeError)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1