From bc9dfd57068f58825d0dc9508b65fcd7977621d4 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sat, 15 Apr 2017 20:20:22 +0900 Subject: [PATCH] fix error handling --- streaming.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/streaming.go b/streaming.go index 68a2c9e..d965b34 100644 --- a/streaming.go +++ b/streaming.go @@ -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) } }()