Skip to content

Commit

Permalink
nil pointer panic, when http body absent
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Jan 28, 2019
1 parent 913f66c commit ea2d262
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func Image(ctx context.Context, filePathOrUrl string) Result {
if err != nil {
return Result{Err: err}
}
defer resp.Body.Close()
defer func() {
if resp.Body != nil {
resp.Body.Close()
}
}()
img = resp.Body
fileName = parsedUrl.Path
} else { // then it's file
Expand Down Expand Up @@ -104,7 +108,9 @@ func getByUrl(ctx context.Context, url string) (*http.Response, error) {
}

if resp.StatusCode != http.StatusOK {
resp.Body.Close()
if resp.Body != nil {
resp.Body.Close()
}
return nil, err
}

Expand Down

0 comments on commit ea2d262

Please sign in to comment.