Skip to content

Commit 7664302

Browse files
author
Andrew Farries
committed
Simplify json decoding of request body
1 parent b0d3d89 commit 7664302

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

components/usage/pkg/stripe/webhook.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package stripe
77
import (
88
"encoding/json"
99
"fmt"
10-
"io/ioutil"
1110
"net/http"
1211

1312
"github.com/gitpod-io/gitpod/common-go/log"
@@ -24,15 +23,10 @@ func (h *WebhookHandler) Handle(w http.ResponseWriter, req *http.Request) {
2423
const maxBodyBytes = int64(65536)
2524

2625
req.Body = http.MaxBytesReader(w, req.Body, maxBodyBytes)
27-
payload, err := ioutil.ReadAll(req.Body)
28-
if err != nil {
29-
log.WithError(err).Error("Stripe webhook error when reading request body")
30-
w.WriteHeader(http.StatusServiceUnavailable)
31-
return
32-
}
3326

3427
event := stripe.Event{}
35-
if err := json.Unmarshal(payload, &event); err != nil {
28+
err := json.NewDecoder(req.Body).Decode(&event)
29+
if err != nil {
3630
log.WithError(err).Error("Stripe webhook error while parsing event payload")
3731
w.WriteHeader(http.StatusBadRequest)
3832
return

0 commit comments

Comments
 (0)