handle errors making or taking offers with insufficient funds

This commit is contained in:
woodser 2021-12-07 17:00:58 -05:00
parent abfc0503fa
commit dd68760f27
6 changed files with 25 additions and 6 deletions

View File

@ -17,6 +17,8 @@
package bisq.common.taskrunner;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -64,7 +66,11 @@ public abstract class Task<T extends Model> {
}
protected void failed(Throwable t) {
log.error(errorMessage, t);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
errorMessage = sw.toString();
log.error(t.getMessage(), t);
taskHandler.handleErrorMessage(errorMessage);
}

View File

@ -732,7 +732,13 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
initTradeAndProtocol(trade, tradeProtocol);
((TakerProtocol) tradeProtocol).onTakeOffer(tradeResultHandler);
// take offer and persist trade on success
((TakerProtocol) tradeProtocol).onTakeOffer(result -> {
tradeResultHandler.handleResult(trade);
}, errorMessage -> {
removeTrade(trade);
errorMessageHandler.handleErrorMessage(errorMessage);
});
requestPersistence();
}
},

View File

@ -90,7 +90,7 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
// TODO (woodser): this implementation is duplicated with SellerAsTakerProtocol
@Override
public void onTakeOffer(TradeResultHandler tradeResultHandler) {
public void onTakeOffer(TradeResultHandler tradeResultHandler, ErrorMessageHandler errorMessageHandler) {
System.out.println("onTakeOffer()");
this.tradeResultHandler = tradeResultHandler;
@ -101,6 +101,9 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
ApplyFilter.class,
TakerReservesTradeFunds.class,
TakerSendsInitTradeRequestToArbitrator.class) // TODO (woodser): app hangs if this pipeline fails. use .using() like below
.using(new TradeTaskRunner(trade,
() -> { },
errorMessageHandler))
.withTimeout(30))
.executeTasks();
}

View File

@ -82,7 +82,8 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onTakeOffer(TradeResultHandler tradeResultHandler) {
public void onTakeOffer(TradeResultHandler tradeResultHandler,
ErrorMessageHandler errorMessageHandler) {
System.out.println("onTakeOffer()");
this.tradeResultHandler = tradeResultHandler;
@ -93,6 +94,9 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
ApplyFilter.class,
TakerReservesTradeFunds.class,
TakerSendsInitTradeRequestToArbitrator.class)
.using(new TradeTaskRunner(trade,
() -> { },
errorMessageHandler))
.withTimeout(30))
.executeTasks();
}

View File

@ -17,10 +17,11 @@
package bisq.core.trade.protocol;
import bisq.common.handlers.ErrorMessageHandler;
import bisq.core.trade.handlers.TradeResultHandler;
public interface TakerProtocol extends TraderProtocol {
void onTakeOffer(TradeResultHandler tradeResultHandler);
void onTakeOffer(TradeResultHandler tradeResultHandler, ErrorMessageHandler errorMessageHandler);
enum TakerEvent implements FluentProtocol.Event {
TAKE_OFFER

View File

@ -109,7 +109,6 @@ public class GrpcErrorMessageHandler implements ErrorMessageHandler {
takeOfferResponseObserver.onNext(reply);
takeOfferResponseObserver.onCompleted();
} catch (IllegalArgumentException ex) {
log.error("", ex);
exceptionHandler.handleErrorMessage(log,
errorMessage,
responseObserver);