Search in sources :

Example 1 with ForwardOnFailure

use of org.folio.circulation.support.ForwardOnFailure in project mod-circulation by folio-org.

the class RequestByInstanceIdResourceTests method getExpectedErrorMessages.

@Test
void getExpectedErrorMessages() {
    HttpFailure validationError = ValidationErrorFailure.singleValidationError(new ValidationError("validationError", "someParam", "null"));
    String errorMessage = RequestByInstanceIdResource.getErrorMessage(validationError);
    assertTrue(errorMessage.contains("validationError"));
    HttpFailure serverErrorFailure = new ServerErrorFailure("serverError");
    errorMessage = RequestByInstanceIdResource.getErrorMessage(serverErrorFailure);
    assertEquals("serverError", errorMessage);
    HttpFailure badRequestFailure = new BadRequestFailure("badRequestFailure");
    errorMessage = RequestByInstanceIdResource.getErrorMessage(badRequestFailure);
    assertEquals("badRequestFailure", errorMessage);
    Response fakeResponse = new Response(500, "fakeResponseFailure", "text/javascript");
    HttpFailure forwardOnFailure = new ForwardOnFailure(fakeResponse);
    errorMessage = RequestByInstanceIdResource.getErrorMessage(forwardOnFailure);
    assertEquals("fakeResponseFailure", errorMessage);
}
Also used : Response(org.folio.circulation.support.http.client.Response) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) HttpFailure(org.folio.circulation.support.HttpFailure) BadRequestFailure(org.folio.circulation.support.BadRequestFailure) ValidationError(org.folio.circulation.support.http.server.ValidationError) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure) Test(org.junit.jupiter.api.Test)

Example 2 with ForwardOnFailure

use of org.folio.circulation.support.ForwardOnFailure in project mod-circulation by folio-org.

the class UpdateRequestQueueTest method assertFailedOnFailureResponse.

private <T> void assertFailedOnFailureResponse(CompletableFuture<Result<T>> completableFuture) throws Exception {
    Result<T> result = completableFuture.get(5, TimeUnit.SECONDS);
    assertTrue(result.failed());
    assertTrue(result.cause() instanceof ForwardOnFailure);
    ForwardOnFailure forwardResponse = (ForwardOnFailure) result.cause();
    assertThat(forwardResponse.getFailureResponse(), is(serverErrorBatchResponse));
}
Also used : ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure)

Example 3 with ForwardOnFailure

use of org.folio.circulation.support.ForwardOnFailure in project mod-circulation by folio-org.

the class PatronActionSessionRepository method delete.

public CompletableFuture<Result<PatronSessionRecord>> delete(PatronSessionRecord session) {
    var interpreter = new ResponseInterpreter<PatronSessionRecord>().on(204, of(() -> session)).otherwise(response -> {
        log.info("Error has occurred while deleting PatronSessionRecord with id {} and action type {}", session.getId(), session.getActionType().name());
        return failed(new ForwardOnFailure(response));
    });
    log.info("Deleting {}", session);
    return patronActionSessionsStorageClient.delete(session.getId().toString()).thenApply(flatMapResult(interpreter::apply));
}
Also used : ResponseInterpreter(org.folio.circulation.support.http.client.ResponseInterpreter) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure)

Aggregations

ForwardOnFailure (org.folio.circulation.support.ForwardOnFailure)3 BadRequestFailure (org.folio.circulation.support.BadRequestFailure)1 HttpFailure (org.folio.circulation.support.HttpFailure)1 ServerErrorFailure (org.folio.circulation.support.ServerErrorFailure)1 Response (org.folio.circulation.support.http.client.Response)1 ResponseInterpreter (org.folio.circulation.support.http.client.ResponseInterpreter)1 ValidationError (org.folio.circulation.support.http.server.ValidationError)1 Test (org.junit.jupiter.api.Test)1