Skip to content

Commit ea2d262

Browse files
committed
nil pointer panic, when http body absent
1 parent 913f66c commit ea2d262

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

loader/loader.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func Image(ctx context.Context, filePathOrUrl string) Result {
5252
if err != nil {
5353
return Result{Err: err}
5454
}
55-
defer resp.Body.Close()
55+
defer func() {
56+
if resp.Body != nil {
57+
resp.Body.Close()
58+
}
59+
}()
5660
img = resp.Body
5761
fileName = parsedUrl.Path
5862
} else { // then it's file
@@ -104,7 +108,9 @@ func getByUrl(ctx context.Context, url string) (*http.Response, error) {
104108
}
105109

106110
if resp.StatusCode != http.StatusOK {
107-
resp.Body.Close()
111+
if resp.Body != nil {
112+
resp.Body.Close()
113+
}
108114
return nil, err
109115
}
110116

0 commit comments

Comments
 (0)