fix: per-caller context on account lookup, stop on non-websocket receive, sanitize CLI output
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
45f88378a6
commit
136e431917
8 files changed
+89
-7
No files matched your search
@@ -20,7 +20,7 @@ type Handler func(ctx context.Context, m Message)
|
||||
// Connection losses and an unavailable service are retried with an
|
||||
// exponential backoff (1s to 30s), logged at Warn level. Listen returns
|
||||
// early only for errors that retrying cannot fix: ErrNotLinked,
|
||||
// ErrMultipleAccounts, or a 4xx answer (*APIError) to the websocket
|
||||
// ErrMultipleAccounts, ErrNotJSONRPC, or a 4xx answer (*APIError) to the websocket
|
||||
// handshake. A panic in h is recovered and logged at Error level.
|
||||
//
|
||||
// Only one Listen per account should run at a time.
|
||||
@@ -51,7 +51,7 @@ func (c *Client) Listen(ctx context.Context, h Handler) error {
|
||||
|
||||
// permanent reports whether retrying cannot fix err.
|
||||
func permanent(err error) bool {
|
||||
if errors.Is(err, ErrNotLinked) || errors.Is(err, ErrMultipleAccounts) {
|
||||
if errors.Is(err, ErrNotLinked) || errors.Is(err, ErrMultipleAccounts) || errors.Is(err, ErrNotJSONRPC) {
|
||||
return true
|
||||
}
|
||||
var apiErr *APIError
|
||||
@@ -69,6 +69,11 @@ func (c *Client) listenOnce(ctx context.Context, h Handler) (connected bool, err
|
||||
}
|
||||
conn, resp, err := websocket.Dial(ctx, c.wsURL(acct), &websocket.DialOptions{HTTPClient: c.http})
|
||||
if err != nil {
|
||||
if resp != nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
// A plain HTTP answer: the service runs in normal/native mode,
|
||||
// where each GET consumes messages. Retrying would lose them.
|
||||
return false, ErrNotJSONRPC
|
||||
}
|
||||
if resp != nil && resp.StatusCode >= 300 {
|
||||
return false, &APIError{StatusCode: resp.StatusCode, Message: err.Error()}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user