fix error handling

pull/13/head
Yasuhiro Matsumoto 2017-04-15 20:20:22 +09:00
parent 825a0db60c
commit bc9dfd5706
1 changed files with 5 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
@ -86,16 +87,19 @@ func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
if err == nil {
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
resp, err = c.Do(req)
if resp.StatusCode != 200 {
err = fmt.Errorf("bad request: %v", resp.Status)
}
}
if err == nil {
err = handleReader(ctx, q, resp.Body)
resp.Body.Close()
if err == nil {
break
}
} else {
q <- &ErrorEvent{err}
}
resp.Body.Close()
time.Sleep(3 * time.Second)
}
}()