fix integration
This commit is contained in:
@@ -88,6 +88,8 @@ func (c *Client) graphqlRequest(ctx context.Context, query string, variables map
|
||||
return nil, fmt.Errorf("failed to marshal request: %w", err)
|
||||
}
|
||||
|
||||
log.Debug("Sourcegraph GraphQL request to %s: variables=%v", c.baseURL+"/.api/graphql", variables)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/.api/graphql", bytes.NewReader(bodyBytes))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||
@@ -110,9 +112,12 @@ func (c *Client) graphqlRequest(ctx context.Context, query string, variables map
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
log.Warn("Sourcegraph GraphQL error status %d: %s", resp.StatusCode, string(respBody))
|
||||
return nil, fmt.Errorf("unexpected status %d: %s", resp.StatusCode, string(respBody))
|
||||
}
|
||||
|
||||
log.Debug("Sourcegraph GraphQL response: %s", string(respBody))
|
||||
|
||||
var result struct {
|
||||
Data json.RawMessage `json:"data"`
|
||||
Errors []struct {
|
||||
@@ -124,6 +129,7 @@ func (c *Client) graphqlRequest(ctx context.Context, query string, variables map
|
||||
}
|
||||
|
||||
if len(result.Errors) > 0 {
|
||||
log.Warn("Sourcegraph GraphQL errors: %v", result.Errors)
|
||||
return nil, fmt.Errorf("graphql error: %s", result.Errors[0].Message)
|
||||
}
|
||||
|
||||
@@ -139,10 +145,13 @@ func cacheKey(queryType, repo, rev, path string, line, char int) string {
|
||||
func (c *Client) Hover(ctx context.Context, repo, rev, path string, line, char int) (*HoverResult, error) {
|
||||
key := cacheKey("hover", repo, rev, path, line, char)
|
||||
|
||||
log.Debug("Sourcegraph Hover request: repo=%s rev=%s path=%s line=%d char=%d", repo, rev, path, line, char)
|
||||
|
||||
// Try cache first
|
||||
if cached, hit := cache.GetCache().Get(key); hit {
|
||||
var result HoverResult
|
||||
if err := json.Unmarshal([]byte(cached), &result); err == nil {
|
||||
log.Debug("Sourcegraph Hover cache hit")
|
||||
return &result, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user