Introduce APIError type and make ErrorEvent.Err public

This makes it a little bit easier to act on API errors that happen while
streaming.
This commit is contained in:
Alexander Bakker 2023-03-11 12:10:46 +01:00
parent 9faaa4f0dc
commit 972ffb4771
6 changed files with 49 additions and 24 deletions

View file

@ -88,7 +88,7 @@ func (c *WSClient) streamingWS(ctx context.Context, stream, tag string) (chan Ev
func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) error {
conn, err := c.dialRedirect(rawurl)
if err != nil {
q <- &ErrorEvent{err: err}
q <- &ErrorEvent{Err: err}
// End.
return err
@ -103,7 +103,7 @@ func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) er
for {
select {
case <-ctx.Done():
q <- &ErrorEvent{err: ctx.Err()}
q <- &ErrorEvent{Err: ctx.Err()}
// End.
return ctx.Err()
@ -113,7 +113,7 @@ func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) er
var s Stream
err := conn.ReadJSON(&s)
if err != nil {
q <- &ErrorEvent{err: err}
q <- &ErrorEvent{Err: err}
// Reconnect.
break