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

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

parent a5a57a1b
......@@ -22,6 +22,7 @@ var (
errChequebookNoAmount = "did not specify amount"
errChequebookNoWithdraw = "cannot withdraw"
errChequebookNoDeposit = "cannot deposit"
errChequebookInsufficientFunds = "insufficient funds"
errCantLastChequePeer = "cannot get last cheque for peer"
errCantLastCheque = "cannot get last cheque for all peers"
errCannotCash = "cannot cash cheque"
......@@ -298,6 +299,12 @@ func (s *server) chequebookWithdrawHandler(w http.ResponseWriter, r *http.Reques
}
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 {
jsonhttp.InternalServerError(w, errChequebookNoWithdraw)
s.Logger.Debugf("debug api: chequebook withdraw: %v", err)
......@@ -324,6 +331,12 @@ func (s *server) chequebookDepositHandler(w http.ResponseWriter, r *http.Request
}
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 {
jsonhttp.InternalServerError(w, errChequebookNoDeposit)
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