mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-04-24 03:00:15 -04:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user