Skip to content

Commit

Permalink
prevent null pointer issue with contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelwing committed Feb 9, 2022
1 parent 3d53ef7 commit a773046
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"bytes"
"context"
"io"
"io/ioutil"
"net/http"
Expand All @@ -22,6 +23,9 @@ type DefaultHTTPClient struct {
}

func (c *DefaultHTTPClient) Request(req *request) (*DiscordResponse, error) {
if req.ctx == nil {
req.ctx = context.Background()
}
l := zerolog.Ctx(req.ctx)
var reader io.Reader = nil
if req.body != nil {
Expand Down
2 changes: 2 additions & 0 deletions http_client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rest

import (
"context"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestDefaultHTTPClient_Request(t *testing.T) {
method: http.MethodGet,
body: []byte(`test request body`),
contentType: JsonContentType,
ctx: context.Background(),
},
wantResponse: &DiscordResponse{
StatusCode: 200,
Expand Down

0 comments on commit a773046

Please # to comment.