refactor: Trim trailing slashes from the API base URL and enhance API error messages with status codes.

This commit is contained in:
Avisek
2026-02-13 20:38:43 +05:30
committed by Meng Zhuo
parent 1aea912fcd
commit 45351a6a79

View File

@@ -42,7 +42,7 @@ func NewHTTPProvider(apiKey, apiBase, proxy string) *HTTPProvider {
return &HTTPProvider{
apiKey: apiKey,
apiBase: apiBase,
apiBase: strings.TrimRight(apiBase, "/"),
httpClient: client,
}
}
@@ -116,7 +116,7 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API error: %s", string(body))
return nil, fmt.Errorf("API request failed:\n Status: %d\n Body: %s", resp.StatusCode, string(body))
}
return p.parseResponse(body)