Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: potential panics on error #1389

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/api/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
kangmingtay marked this conversation as resolved.
Show resolved Hide resolved
res.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusMultipleChoices {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/sms_provider/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/api/sms_provider/twilio_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading