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

@ -135,13 +135,13 @@ func wsTest(t *testing.T, q chan Event, cancel func()) {
t.Fatalf("want %q but %q", "1234567", events[3].(*DeleteEvent).ID)
}
if errorEvent, ok := events[4].(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Fatalf("should be fail: %v", errorEvent.Err)
}
if errorEvent, ok := events[5].(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Fatalf("should be fail: %v", errorEvent.Err)
}
if errorEvent, ok := events[6].(*ErrorEvent); !ok {
t.Fatalf("should be fail: %v", errorEvent.err)
t.Fatalf("should be fail: %v", errorEvent.Err)
}
}
@ -168,7 +168,7 @@ func TestStreamingWS(t *testing.T) {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Errorf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.Err)
}
}()
wg.Wait()
@ -204,7 +204,7 @@ func TestHandleWS(t *testing.T) {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Errorf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.Err)
}
}()
err := client.handleWS(context.Background(), ":", q)
@ -219,7 +219,7 @@ func TestHandleWS(t *testing.T) {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Errorf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.Err)
}
}()
err = client.handleWS(ctx, "ws://"+ts.Listener.Addr().String(), q)
@ -232,7 +232,7 @@ func TestHandleWS(t *testing.T) {
defer wg.Done()
e := <-q
if errorEvent, ok := e.(*ErrorEvent); !ok {
t.Errorf("should be fail: %v", errorEvent.err)
t.Errorf("should be fail: %v", errorEvent.Err)
}
}()
client.handleWS(context.Background(), "ws://"+ts.Listener.Addr().String(), q)