fix: fail closed on cancelled Connect and timeout RPC fallback
This commit is contained in:
+7
-3
@@ -2,7 +2,10 @@ package rh
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"s1d3sw1ped/robinhood-agentic-mcp/accounts"
|
||||
"s1d3sw1ped/robinhood-agentic-mcp/auth"
|
||||
@@ -18,9 +21,6 @@ import (
|
||||
// Connect reads tokens and returns a wired API. Session connect is preferred;
|
||||
// JSON-RPC tools/call is used when the session cannot be opened. Missing tokens fail closed.
|
||||
func Connect(ctx context.Context, cfg Config) (*API, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg = cfg.WithDefaults()
|
||||
if cfg.TokenFile == "" {
|
||||
return nil, fmt.Errorf("connect: missing TokenFile")
|
||||
@@ -34,11 +34,15 @@ func Connect(ctx context.Context, cfg Config) (*API, error) {
|
||||
}
|
||||
c, err := client.ConnectSession(ctx, cfg.URL, auth.ClientToken(tok), cfg.Name, cfg.Version)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return nil, err
|
||||
}
|
||||
c = &client.Client{
|
||||
URL: cfg.URL,
|
||||
Token: tok.AccessToken,
|
||||
Name: cfg.Name,
|
||||
Version: cfg.Version,
|
||||
HTTP: &http.Client{Timeout: 60 * time.Second},
|
||||
}
|
||||
}
|
||||
return &API{
|
||||
|
||||
Reference in New Issue
Block a user