mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-24 14:59:37 -05:00
handle errors making or taking offers with insufficient funds
This commit is contained in:
parent
abfc0503fa
commit
dd68760f27
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user