diff --git a/.golangci.yml b/.golangci.yml index cb4026d7..bc041fa1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,14 +7,14 @@ linters: - errcheck # Mandatory. Do not disable. - ineffassign # Mandatory. Do not disable. - staticcheck # Mandatory. Do not disable. + - gosec + - bodyclose # https://github.com/timakin/bodyclose - gomodguard - nolintlint # TODO: -# - bodyclose # https://github.com/timakin/bodyclose # - gocritic # - goimports -# - gosec # - gosimple # - govet # - noctx diff --git a/exports.go b/exports.go index a2bbece9..5b94ab2a 100644 --- a/exports.go +++ b/exports.go @@ -93,14 +93,23 @@ func (mg *MailgunImpl) GetExportLink(ctx context.Context, id string) (string, er resp, err := r.Client.Do(req) if err != nil { - if resp != nil && resp.StatusCode == http.StatusFound { - url, err := resp.Location() - if err != nil { - return "", fmt.Errorf("while parsing 302 redirect url: %s", err) + if resp != nil { // TODO(vtopc): not nil err and resp at the same time, is that possible at all? + defer resp.Body.Close() + + if resp.StatusCode == http.StatusFound { + url, err := resp.Location() + if err != nil { + return "", fmt.Errorf("while parsing 302 redirect url: %s", err) + } + + return url.String(), nil } - return url.String(), nil } + return "", err } + + defer resp.Body.Close() + return "", fmt.Errorf("expected a 302 response, API returned a '%d' instead", resp.StatusCode) } diff --git a/rest_shim.go b/rest_shim.go index 1a163fd8..93990e0b 100644 --- a/rest_shim.go +++ b/rest_shim.go @@ -11,7 +11,7 @@ import ( // this user agent allows them to identify the client from human-generated activity. const MailgunGoUserAgent = "mailgun-go/" + Version -// This error will be returned whenever a Mailgun API returns an error response. +// UnexpectedResponseError this error will be returned whenever a Mailgun API returns an error response. // Your application can check the Actual field to see the actual HTTP response code returned. // URL contains the base URL accessed, sans any query parameters. type UnexpectedResponseError struct { diff --git a/version.go b/version.go index fc25a55d..84a86987 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,5 @@ package mailgun // Version of current release -const Version = "4.6.1" +// TODO(vtopc): automate this +const Version = "4.18.5"