diff --git a/push/service.go b/push/service.go index 70f40c5..3466a63 100644 --- a/push/service.go +++ b/push/service.go @@ -7,7 +7,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "net/http" "strconv" "time" @@ -178,16 +177,12 @@ func (s *Service) PushBytes(deviceToken string, headers *Headers, payload []byte return resp.Header.Get("apns-id"), nil } - // read entire response body - // TODO: could decode while reading instead - body, err := ioutil.ReadAll(resp.Body) + var response response + err = json.NewDecoder(resp.Body).Decode(&response) if err != nil { return "", err } - var response response - json.Unmarshal(body, &response) - e, ok := errorReason[response.Reason] if !ok { // fallback to HTTP status codes if reason not found in JSON