Skip to content

Commit

Permalink
Treat db errors when fetching purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
llemeurfr committed Mar 22, 2020
1 parent 7e7349d commit 646793a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions frontend/api/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ func GetPurchases(w http.ResponseWriter, r *http.Request, s IServer) {
purchases := make([]webpurchase.Purchase, 0)
fn := s.PurchaseAPI().List(pagination.PerPage, pagination.Page)

for it, err := fn(); err == nil; it, err = fn() {
purchases = append(purchases, it)
var purchase webpurchase.Purchase
for purchase, err = fn(); err == nil && purchase.ID != 0; purchase, err = fn() {
purchases = append(purchases, purchase)
}
if err != nil {
problem.Error(w, r, problem.Problem{Detail: err.Error()}, http.StatusInternalServerError)
return
}

PrepareListHeaderResponse(len(purchases), "/api/v1/purchases", pagination, w)
Expand Down Expand Up @@ -85,8 +90,14 @@ func GetUserPurchases(w http.ResponseWriter, r *http.Request, s IServer) {

purchases := make([]webpurchase.Purchase, 0)
fn := s.PurchaseAPI().ListByUser(userId, pagination.PerPage, pagination.Page)
for it, err := fn(); err == nil; it, err = fn() {
purchases = append(purchases, it)

var purchase webpurchase.Purchase
for purchase, err = fn(); err == nil && purchase.ID != 0; purchase, err = fn() {
purchases = append(purchases, purchase)
}
if err != nil {
problem.Error(w, r, problem.Problem{Detail: err.Error()}, http.StatusInternalServerError)
return
}

PrepareListHeaderResponse(len(purchases), "/api/v1/users/"+vars["user_id"]+"/purchases", pagination, w)
Expand Down

0 comments on commit 646793a

Please sign in to comment.