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