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

callback works if a request end with error #186

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions gorequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,23 +977,25 @@ func (s *SuperAgent) End(callback ...func(response Response, body string, errs [
// EndBytes should be used when you want the body as bytes. The callbacks work the same way as with `End`, except that a byte array is used instead of a string.
func (s *SuperAgent) EndBytes(callback ...func(response Response, body []byte, errs []error)) (Response, []byte, []error) {
var (
errs []error
resp Response
body []byte
errs []error
resp Response
body []byte
respCallback http.Response
)

for {
resp, body, errs = s.getResponseBytes()
if errs != nil {
return nil, nil, errs
break
}

if s.isRetryableRequest(resp) {
resp.Header.Set("Retry-Count", strconv.Itoa(s.Retryable.Attempt))
respCallback = *resp
break
}
}

respCallback := *resp
if len(callback) != 0 {
callback[0](&respCallback, body, s.Errors)
}
Expand Down