Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Jun 24, 2021
1 parent 9abb082 commit 36a222a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
27 changes: 18 additions & 9 deletions stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ type APIResource struct {
LastResponse *APIResponse `json:"-"`
}

// APIResource is a type assigned to structs that may come from Stripe API
// endpoints and contains facilities common to all of them.
// APIStream is a type assigned to streaming responses that may come from Stripe API
type APIStream struct {
LastResponse *StreamingAPIResponse `json:"-"`
}
Expand Down Expand Up @@ -598,16 +597,26 @@ func (s *BackendImplementation) logError(statusCode int, err error) {

func (s *BackendImplementation) DoStreaming(req *http.Request, body *bytes.Buffer, v StreamingLastResponseSetter) error {
handleResponse := func(res *http.Response, err error) (interface{}, error) {

// Some sort of connection error
if err != nil {
s.LeveledLogger.Errorf("Request failed with error: %v", err)
} else if res.StatusCode >= 400 {
var resBody []byte
if err == nil {
resBody, err = ioutil.ReadAll(res.Body)
res.Body.Close()
}
err = s.ResponseToError(res, resBody)
return res.Body, err
}

// Successful response, return the body ReadCloser
if res.StatusCode < 400 {
return res.Body, err
}

// Failure: try and parse the json of the response
// when logging the error
var resBody []byte
resBody, err = ioutil.ReadAll(res.Body)
res.Body.Close()
if err == nil {
err = s.ResponseToError(res, resBody)
} else {
s.logError(res.StatusCode, err)
}

Expand Down
3 changes: 0 additions & 3 deletions stripe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,6 @@ func TestDoStreaming_ParsableError(t *testing.T) {
}

func TestDoStreaming_UnparsableError(t *testing.T) {
type testServerResponse struct {
Error *Error `json:"error"`
}
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
var data []byte
Expand Down

0 comments on commit 36a222a

Please sign in to comment.