diff --git a/internal/api/provider/provider.go b/internal/api/provider/provider.go index c16272ab01..857e88252d 100644 --- a/internal/api/provider/provider.go +++ b/internal/api/provider/provider.go @@ -114,7 +114,6 @@ func makeRequest(ctx context.Context, tok *oauth2.Token, g *oauth2.Config, url s defer utilities.SafeClose(res.Body) bodyBytes, _ := io.ReadAll(res.Body) - defer utilities.SafeClose(res.Body) res.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusMultipleChoices { diff --git a/internal/api/sms_provider/twilio.go b/internal/api/sms_provider/twilio.go index 10af4e6371..3705635d80 100644 --- a/internal/api/sms_provider/twilio.go +++ b/internal/api/sms_provider/twilio.go @@ -112,10 +112,10 @@ func (t *TwilioProvider) SendSms(phone, message, channel, otp string) (string, e r.Header.Add("Content-Type", "application/x-www-form-urlencoded") r.SetBasicAuth(t.Config.AccountSid, t.Config.AuthToken) res, err := client.Do(r) - defer utilities.SafeClose(res.Body) if err != nil { return "", err } + defer utilities.SafeClose(res.Body) if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated { resp := &twilioErrResponse{} if err := json.NewDecoder(res.Body).Decode(resp); err != nil { diff --git a/internal/api/sms_provider/twilio_verify.go b/internal/api/sms_provider/twilio_verify.go index bed3ff0ae3..8ec546396b 100644 --- a/internal/api/sms_provider/twilio_verify.go +++ b/internal/api/sms_provider/twilio_verify.go @@ -78,10 +78,10 @@ func (t *TwilioVerifyProvider) SendSms(phone, message, channel string) (string, r.Header.Add("Content-Type", "application/x-www-form-urlencoded") r.SetBasicAuth(t.Config.AccountSid, t.Config.AuthToken) res, err := client.Do(r) - defer utilities.SafeClose(res.Body) if err != nil { return "", err } + defer utilities.SafeClose(res.Body) if !(res.StatusCode == http.StatusOK || res.StatusCode == http.StatusCreated) { resp := &twilioErrResponse{} if err := json.NewDecoder(res.Body).Decode(resp); err != nil { @@ -114,10 +114,10 @@ func (t *TwilioVerifyProvider) VerifyOTP(phone, code string) error { r.Header.Add("Content-Type", "application/x-www-form-urlencoded") r.SetBasicAuth(t.Config.AccountSid, t.Config.AuthToken) res, err := client.Do(r) - defer utilities.SafeClose(res.Body) if err != nil { return err } + defer utilities.SafeClose(res.Body) if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated { resp := &twilioErrResponse{} if err := json.NewDecoder(res.Body).Decode(resp); err != nil {