Skip to content

Commit

Permalink
satellite: invalid coupon code returns 400 status code
Browse files Browse the repository at this point in the history
fixes: #4782

Change-Id: Idcc00202ed91a10c280f706e14d4901bf2f61541
  • Loading branch information
Lizzy Thomson authored and Lizzy Thomson committed Oct 31, 2022
1 parent f76abb3 commit 23917e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions satellite/console/consoleweb/consoleapi/payments.go
Expand Up @@ -16,6 +16,7 @@ import (
"go.uber.org/zap"

"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments/stripecoinpayments"
)

var (
Expand Down Expand Up @@ -278,6 +279,10 @@ func (p *Payments) ApplyCouponCode(w http.ResponseWriter, r *http.Request) {

coupon, err := p.service.Payments().ApplyCouponCode(ctx, couponCode)
if err != nil {
if stripecoinpayments.ErrInvalidCoupon.Has(err) {
p.serveJSONError(w, http.StatusBadRequest, err)
return
}
p.serveJSONError(w, http.StatusInternalServerError, err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion satellite/payments/stripecoinpayments/coupons.go
Expand Up @@ -31,7 +31,7 @@ func (coupons *coupons) ApplyCouponCode(ctx context.Context, userID uuid.UUID, c
Code: stripe.String(couponCode),
})
if !promoCodeIter.Next() {
return nil, Error.New("Invalid coupon code")
return nil, ErrInvalidCoupon.New("Invalid coupon code")
}
promoCode := promoCodeIter.PromotionCode()

Expand Down
3 changes: 3 additions & 0 deletions satellite/payments/stripecoinpayments/service.go
Expand Up @@ -33,6 +33,9 @@ var (
// Error defines stripecoinpayments service error.
Error = errs.Class("stripecoinpayments service")

// ErrInvalidCoupon defines invalid coupon code error.
ErrInvalidCoupon = errs.Class("invalid coupon code")

mon = monkit.Package()
)

Expand Down

0 comments on commit 23917e5

Please sign in to comment.