Skip to content

Commit 52e6aa3

Browse files
author
Akshay Chawla
committed
returning error message with code
1 parent 5b8b5ab commit 52e6aa3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/file/external_file_operator.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ func (efo *ExternalFileOperator) downloadFileContent(ctx context.Context, file *
161161

162162
return nil, h, nil
163163
default:
164+
const maxErrBody = 4096
165+
var bodyMsg string
166+
167+
limited := io.LimitReader(resp.Body, maxErrBody)
168+
b, readErr := io.ReadAll(limited)
169+
if readErr != nil {
170+
slog.DebugContext(ctx, "Failed to read error response body", "error", readErr, "status", resp.StatusCode)
171+
} else {
172+
bodyMsg = strings.TrimSpace(string(b))
173+
}
174+
175+
if bodyMsg != "" {
176+
return nil, DownloadHeader{}, fmt.Errorf("download failed with status code %d: %s",
177+
resp.StatusCode, bodyMsg)
178+
}
179+
164180
return nil, DownloadHeader{}, fmt.Errorf("download failed with status code %d", resp.StatusCode)
165181
}
166182

0 commit comments

Comments
 (0)