Commit 2cd1a10f authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

better error if insufficient funds for user action (#1002)

parent a5a57a1b
...@@ -18,16 +18,17 @@ import ( ...@@ -18,16 +18,17 @@ import (
) )
var ( var (
errChequebookBalance = "cannot get chequebook balance" errChequebookBalance = "cannot get chequebook balance"
errChequebookNoAmount = "did not specify amount" errChequebookNoAmount = "did not specify amount"
errChequebookNoWithdraw = "cannot withdraw" errChequebookNoWithdraw = "cannot withdraw"
errChequebookNoDeposit = "cannot deposit" errChequebookNoDeposit = "cannot deposit"
errCantLastChequePeer = "cannot get last cheque for peer" errChequebookInsufficientFunds = "insufficient funds"
errCantLastCheque = "cannot get last cheque for all peers" errCantLastChequePeer = "cannot get last cheque for peer"
errCannotCash = "cannot cash cheque" errCantLastCheque = "cannot get last cheque for all peers"
errCannotCashStatus = "cannot get cashout status" errCannotCash = "cannot cash cheque"
errNoCashout = "no prior cashout" errCannotCashStatus = "cannot get cashout status"
errNoCheque = "no prior cheque" errNoCashout = "no prior cashout"
errNoCheque = "no prior cheque"
) )
type chequebookBalanceResponse struct { type chequebookBalanceResponse struct {
...@@ -298,6 +299,12 @@ func (s *server) chequebookWithdrawHandler(w http.ResponseWriter, r *http.Reques ...@@ -298,6 +299,12 @@ func (s *server) chequebookWithdrawHandler(w http.ResponseWriter, r *http.Reques
} }
txHash, err := s.Chequebook.Withdraw(r.Context(), amount) txHash, err := s.Chequebook.Withdraw(r.Context(), amount)
if errors.Is(err, chequebook.ErrInsufficientFunds) {
jsonhttp.BadRequest(w, errChequebookInsufficientFunds)
s.Logger.Debugf("debug api: chequebook withdraw: %v", err)
s.Logger.Error("debug api: cannot withdraw from chequebook")
return
}
if err != nil { if err != nil {
jsonhttp.InternalServerError(w, errChequebookNoWithdraw) jsonhttp.InternalServerError(w, errChequebookNoWithdraw)
s.Logger.Debugf("debug api: chequebook withdraw: %v", err) s.Logger.Debugf("debug api: chequebook withdraw: %v", err)
...@@ -324,6 +331,12 @@ func (s *server) chequebookDepositHandler(w http.ResponseWriter, r *http.Request ...@@ -324,6 +331,12 @@ func (s *server) chequebookDepositHandler(w http.ResponseWriter, r *http.Request
} }
txHash, err := s.Chequebook.Deposit(r.Context(), amount) txHash, err := s.Chequebook.Deposit(r.Context(), amount)
if errors.Is(err, chequebook.ErrInsufficientFunds) {
jsonhttp.BadRequest(w, errChequebookInsufficientFunds)
s.Logger.Debugf("debug api: chequebook deposit: %v", err)
s.Logger.Error("debug api: cannot deposit from chequebook")
return
}
if err != nil { if err != nil {
jsonhttp.InternalServerError(w, errChequebookNoDeposit) jsonhttp.InternalServerError(w, errChequebookNoDeposit)
s.Logger.Debugf("debug api: chequebook deposit: %v", err) s.Logger.Debugf("debug api: chequebook deposit: %v", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment