Search in sources :

Example 1 with NotFoundException

use of io.bisq.api.NotFoundException in project bisq-api by mrosseel.

the class TradeResource method handlePaymentStatusChange.

private void handlePaymentStatusChange(String tradeId, AsyncResponse asyncResponse, CompletableFuture<Void> completableFuture) {
    completableFuture.thenApply(response -> asyncResponse.resume(Response.status(Response.Status.OK).build())).exceptionally(e -> {
        final Throwable cause = e.getCause();
        final Response.ResponseBuilder responseBuilder;
        if (cause instanceof ValidationException) {
            responseBuilder = toValidationErrorResponse(cause, 422);
        } else if (cause instanceof NotFoundException) {
            responseBuilder = toValidationErrorResponse(cause, 404);
        } else {
            final String message = cause.getMessage();
            responseBuilder = Response.status(500);
            if (null != message)
                responseBuilder.entity(new ValidationErrorMessage(ImmutableList.of(message)));
            log.error("Unable to confirm payment started for trade: " + tradeId, cause);
        }
        return asyncResponse.resume(responseBuilder.build());
    });
}
Also used : TradeDetails(io.bisq.api.model.TradeDetails) AsyncResponse(javax.ws.rs.container.AsyncResponse) TradeList(io.bisq.api.model.TradeList) CompletableFuture(java.util.concurrent.CompletableFuture) Suspended(javax.ws.rs.container.Suspended) ApiOperation(io.swagger.annotations.ApiOperation) Slf4j(lombok.extern.slf4j.Slf4j) MediaType(javax.ws.rs.core.MediaType) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) BisqProxy(io.bisq.api.BisqProxy) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ValidationException(javax.validation.ValidationException) NotFoundException(io.bisq.api.NotFoundException) NotEmpty(org.hibernate.validator.constraints.NotEmpty) ResourceHelper.toValidationErrorResponse(io.bisq.api.service.ResourceHelper.toValidationErrorResponse) ValidationErrorMessage(io.dropwizard.jersey.validation.ValidationErrorMessage) Api(io.swagger.annotations.Api) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) ResourceHelper.toValidationErrorResponse(io.bisq.api.service.ResourceHelper.toValidationErrorResponse) ValidationException(javax.validation.ValidationException) NotFoundException(io.bisq.api.NotFoundException) ValidationErrorMessage(io.dropwizard.jersey.validation.ValidationErrorMessage)

Example 2 with NotFoundException

use of io.bisq.api.NotFoundException in project bisq-api by mrosseel.

the class OfferResource method takeOffer.

@ApiOperation(value = "Take offer", response = TradeDetails.class)
@POST
@Path("/{id}/take")
public void takeOffer(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id, @Valid TakeOffer data) {
    // TODO how do we go about not blocking this REST thread?
    final CompletableFuture<Trade> completableFuture = bisqProxy.offerTake(id, data.paymentAccountId, data.amount, true);
    completableFuture.thenApply(trade -> asyncResponse.resume(new TradeDetails(trade))).exceptionally(e -> {
        final Throwable cause = e.getCause();
        final Response.ResponseBuilder responseBuilder;
        if (cause instanceof ValidationException) {
            final int status = 422;
            responseBuilder = toValidationErrorResponse(cause, status);
        } else if (cause instanceof IncompatiblePaymentAccountException) {
            responseBuilder = toValidationErrorResponse(cause, 423);
        } else if (cause instanceof NoAcceptedArbitratorException) {
            responseBuilder = toValidationErrorResponse(cause, 424);
        } else if (cause instanceof PaymentAccountNotFoundException) {
            responseBuilder = toValidationErrorResponse(cause, 425);
        } else if (cause instanceof InsufficientMoneyException) {
            responseBuilder = toValidationErrorResponse(cause, 427);
        } else if (cause instanceof NotFoundException) {
            responseBuilder = toValidationErrorResponse(cause, 404);
        } else {
            final String message = cause.getMessage();
            responseBuilder = Response.status(500);
            if (null != message)
                responseBuilder.entity(new ValidationErrorMessage(ImmutableList.of(message)));
            log.error("Unable to take offer: " + id + " " + Json.pretty(data), cause);
        }
        return asyncResponse.resume(responseBuilder.build());
    });
}
Also used : io.bisq.api(io.bisq.api) AsyncResponse(javax.ws.rs.container.AsyncResponse) Json(io.swagger.util.Json) CompletableFuture(java.util.concurrent.CompletableFuture) Suspended(javax.ws.rs.container.Suspended) Offer(io.bisq.core.offer.Offer) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ResourceHelper(io.bisq.api.service.ResourceHelper) Slf4j(lombok.extern.slf4j.Slf4j) MediaType(javax.ws.rs.core.MediaType) Collectors.toList(java.util.stream.Collectors.toList) Trade(io.bisq.core.trade.Trade) ImmutableList(com.google.common.collect.ImmutableList) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) ValidationException(javax.validation.ValidationException) NotFoundException(io.bisq.api.NotFoundException) io.bisq.api.model(io.bisq.api.model) NotEmpty(org.hibernate.validator.constraints.NotEmpty) ResourceHelper.toValidationErrorResponse(io.bisq.api.service.ResourceHelper.toValidationErrorResponse) ValidationErrorMessage(io.dropwizard.jersey.validation.ValidationErrorMessage) Api(io.swagger.annotations.Api) ValidationException(javax.validation.ValidationException) NotFoundException(io.bisq.api.NotFoundException) ValidationErrorMessage(io.dropwizard.jersey.validation.ValidationErrorMessage) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) ResourceHelper.toValidationErrorResponse(io.bisq.api.service.ResourceHelper.toValidationErrorResponse) Trade(io.bisq.core.trade.Trade) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 NotFoundException (io.bisq.api.NotFoundException)2 ResourceHelper.toValidationErrorResponse (io.bisq.api.service.ResourceHelper.toValidationErrorResponse)2 ValidationErrorMessage (io.dropwizard.jersey.validation.ValidationErrorMessage)2 Api (io.swagger.annotations.Api)2 ApiOperation (io.swagger.annotations.ApiOperation)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Collectors.toList (java.util.stream.Collectors.toList)2 ValidationException (javax.validation.ValidationException)2 javax.ws.rs (javax.ws.rs)2 AsyncResponse (javax.ws.rs.container.AsyncResponse)2 Suspended (javax.ws.rs.container.Suspended)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2 Slf4j (lombok.extern.slf4j.Slf4j)2 NotEmpty (org.hibernate.validator.constraints.NotEmpty)2 io.bisq.api (io.bisq.api)1 BisqProxy (io.bisq.api.BisqProxy)1 io.bisq.api.model (io.bisq.api.model)1 TradeDetails (io.bisq.api.model.TradeDetails)1