Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logs to budget withdraw #1661

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,10 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
body, err := io.ReadAll(r.Body)
r.Body.Close()

err = json.Unmarshal(body, &request)
if err != nil {
merr := json.Unmarshal(body, &request)
if merr != nil {
w.WriteHeader(http.StatusNotAcceptable)
log.Println("Could not marshal WithdrawRequest")
return
}

Expand All @@ -611,6 +612,7 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
hasRole := h.userHasAccess(pubKeyFromAuth, request.OrgUuid, db.WithdrawBudget)
if !hasRole {
w.WriteHeader(http.StatusUnauthorized)
log.Printf("User %s on Workspace %s doesn't have appropriate permissions to withdraw bounty budget", pubKeyFromAuth, request.OrgUuid)
errMsg := formatPayError("You don't have appropriate permissions to withdraw bounty budget")
json.NewEncoder(w).Encode(errMsg)
return
Expand All @@ -632,13 +634,16 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
if paymentSuccess.Success {
// withdraw amount from workspace budget
h.db.WithdrawBudget(pubKeyFromAuth, request.OrgUuid, amount)
log.Printf("Paid Lightning invoice %s and withdrew from workspace %s budget", request.PaymentRequest, request.OrgUuid)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(paymentSuccess)
} else {
log.Printf("Could not pay Lightning invoice %s", request.PaymentRequest)
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(paymentError)
}
} else {
log.Printf("Budget Balance Error amount %d exceeds Workspace %s budget balance", amount, request.OrgUuid)
w.WriteHeader(http.StatusForbidden)
errMsg := formatPayError("Could not pay lightning invoice")
json.NewEncoder(w).Encode(errMsg)
Expand Down
Loading