[MM-57489] Check for StatusCode when receiving responses from the push proxy (#27392)

This commit is contained in:
Devin Binnie 2024-06-19 09:18:26 -04:00 committed by GitHub
parent 3a890e1c90
commit f41e8ad756
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -490,6 +490,10 @@ func (a *App) rawSendToPushProxy(msg *model.PushNotification) (model.PushRespons
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("response returned error code: %d", resp.StatusCode)
}
var pushResponse model.PushResponse
if err := json.NewDecoder(resp.Body).Decode(&pushResponse); err != nil {
return nil, fmt.Errorf("failed to decode from JSON: %w", err)
@ -562,6 +566,10 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("response returned error code: %d", resp.StatusCode)
}
// Reading the body to completion.
_, err = io.Copy(io.Discard, resp.Body)
return err