fix: improve error message truncation in DirectlyGetModels method

## CHANGES

- Add proper bounds checking for response body truncation
- Prevent slice out of bounds errors in error messages
- Add ellipsis indicator when response body is truncated
- Improve error message clarity for debugging purposes
This commit is contained in:
Kayvan Sylvan
2025-07-11 13:33:16 -07:00
parent ecac2b4c34
commit e1945a0b62

View File

@@ -88,7 +88,13 @@ func (c *Client) DirectlyGetModels(ctx context.Context) ([]string, error) {
return extractModelIDs(directArray), nil
}
return nil, fmt.Errorf("unable to parse models response; raw response: %s", string(bodyBytes)[:errorResponseLimit])
var truncatedBody string
if len(bodyBytes) > errorResponseLimit {
truncatedBody = string(bodyBytes[:errorResponseLimit]) + "..."
} else {
truncatedBody = string(bodyBytes)
}
return nil, fmt.Errorf("unable to parse models response; raw response: %s", truncatedBody)
}
func extractModelIDs(models []Model) []string {