MCPcopy
hub / github.com/dosco/graphjin / Call

Method Call

core/openapi/caller.go:58–87  ·  view source on GitHub ↗

Call executes the operation and returns the response body, with the configured ResultPath stripped. A 401 triggers exactly one retry after invalidating the auth provider's cached token — this handles the common case of a service-credential token expiring mid-flight.

(ctx context.Context, p CallParams)

Source from the content-addressed store, hash-verified

56// after invalidating the auth provider's cached token — this handles
57// the common case of a service-credential token expiring mid-flight.
58func (c *Caller) Call(ctx context.Context, p CallParams) ([]byte, error) {
59 body, status, err := c.doOnce(ctx, p)
60 if err != nil {
61 return nil, err
62 }
63 if status == http.StatusUnauthorized {
64 // Cached-token providers invalidate; stateless ones no-op.
65 // Either way, we retry exactly once. Repeat 401s after refresh
66 // surface as a real auth failure rather than a retry loop.
67 if rerr := c.auth.OnUnauthorized(ctx); rerr != nil {
68 return nil, fmt.Errorf("openapi: auth invalidate: %w", rerr)
69 }
70 body, status, err = c.doOnce(ctx, p)
71 if err != nil {
72 return nil, err
73 }
74 }
75 if status/100 != 2 {
76 return nil, fmt.Errorf("openapi: %s %s returned %d: %s",
77 c.op.Method, c.op.PathTemplate, status, truncate(body, 200))
78 }
79
80 if len(c.op.ResultPath) > 0 {
81 body, err = stripResultPath(body, c.op.ResultPath)
82 if err != nil {
83 return nil, fmt.Errorf("openapi: %s strip result_path: %w", c.op.OperationID, err)
84 }
85 }
86 return body, nil
87}
88
89// doOnce builds and executes a single HTTP request. Separated out so
90// the 401-retry path can call it twice without re-building the URL

Callers

nothing calls this directly

Calls 4

doOnceMethod · 0.95
stripResultPathFunction · 0.85
truncateFunction · 0.70
OnUnauthorizedMethod · 0.65

Tested by

no test coverage detected