Search in sources :

Example 1 with ExternalResourceFetchException

use of org.folio.inventory.exceptions.ExternalResourceFetchException in project mod-inventory by folio-org.

the class CollectionResourceRepository method handleResponse.

private CompletableFuture<Response> handleResponse(Response response, int expectedStatusCode) {
    if (response.getStatusCode() != expectedStatusCode) {
        final CompletableFuture<Response> failed = new CompletableFuture<>();
        failed.completeExceptionally(new ExternalResourceFetchException(response));
        return failed;
    }
    return CompletableFuture.completedFuture(response);
}
Also used : Response(org.folio.inventory.support.http.client.Response) CompletableFuture(java.util.concurrent.CompletableFuture) ExternalResourceFetchException(org.folio.inventory.exceptions.ExternalResourceFetchException)

Example 2 with ExternalResourceFetchException

use of org.folio.inventory.exceptions.ExternalResourceFetchException in project mod-inventory by folio-org.

the class MultipleRecordsFetchClient method getAllMatched.

private CompletableFuture<Response> getAllMatched(CqlQuery query) {
    final CompletableFuture<Response> future = new CompletableFuture<>();
    resourceClient.getAll(query.toString(), future::complete);
    return future.thenCompose(response -> {
        if (response.getStatusCode() != expectedStatus) {
            return CompletableFutures.failedFuture(new ExternalResourceFetchException(response));
        }
        return CompletableFuture.completedFuture(response);
    });
}
Also used : Response(org.folio.inventory.support.http.client.Response) CompletableFuture(java.util.concurrent.CompletableFuture) ExternalResourceFetchException(org.folio.inventory.exceptions.ExternalResourceFetchException)

Example 3 with ExternalResourceFetchException

use of org.folio.inventory.exceptions.ExternalResourceFetchException in project mod-inventory by folio-org.

the class EndpointFailureHandler method handleFailure.

public static void handleFailure(Throwable failure, RoutingContext context) {
    final Throwable failureToHandle = getKnownException(failure);
    if (failureToHandle instanceof UnprocessableEntityException) {
        UnprocessableEntityException validationFailure = (UnprocessableEntityException) failureToHandle;
        unprocessableEntity(context.response(), validationFailure.getMessage(), validationFailure.getPropertyName(), validationFailure.getPropertyValue());
    } else if (failureToHandle instanceof NotFoundException) {
        ClientErrorResponse.notFound(context.response(), failureToHandle.getMessage());
    } else if (failureToHandle instanceof ExternalResourceFetchException) {
        final ExternalResourceFetchException externalException = (ExternalResourceFetchException) failureToHandle;
        forward(context.response(), externalException.getBody(), externalException.getStatusCode(), externalException.getContentType());
    } else {
        ServerErrorResponse.internalError(context.response(), failureToHandle);
    }
}
Also used : UnprocessableEntityException(org.folio.inventory.exceptions.UnprocessableEntityException) ExternalResourceFetchException(org.folio.inventory.exceptions.ExternalResourceFetchException) NotFoundException(org.folio.inventory.exceptions.NotFoundException)

Aggregations

ExternalResourceFetchException (org.folio.inventory.exceptions.ExternalResourceFetchException)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 Response (org.folio.inventory.support.http.client.Response)2 NotFoundException (org.folio.inventory.exceptions.NotFoundException)1 UnprocessableEntityException (org.folio.inventory.exceptions.UnprocessableEntityException)1