Skip to content

Commit

Permalink
Export HTTPError
Browse files Browse the repository at this point in the history
Lets callers use `errors.As` to differentiate transient outages from license problems.

fixes #341
  • Loading branch information
ryepup committed Nov 5, 2024
1 parent 447ee5b commit 27c4b81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion client/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/maxmind/geoipupdate/v7/internal/vars"
)

// HTTPError is an error from performing an HTTP request and receiving a non-200 status code.
//
// See https://dev.maxmind.com/geoip/docs/web-services/responses/#errors for more details.
type HTTPError = internal.HTTPError

// DownloadResponse describes the result of a Download call.
type DownloadResponse struct {
// LastModified is the date that the database was last modified. It will
Expand Down Expand Up @@ -55,6 +60,9 @@ type DownloadResponse struct {
//
// If the current MD5 checksum matches what the server currently has, no
// download is performed.
//
// Returns an [HTTPError] if the server returns a non-200 status code. This
// can be used to identify problems with license.
func (c Client) Download(
ctx context.Context,
editionID,
Expand Down Expand Up @@ -125,7 +133,7 @@ func (c *Client) download(
// TODO(horgh): Should we fully consume the body?
//nolint:errcheck // we are already returning an error.
buf, _ := io.ReadAll(io.LimitReader(response.Body, 256))
httpErr := internal.HTTPError{
httpErr := HTTPError{
Body: string(buf),
StatusCode: response.StatusCode,
}
Expand Down
3 changes: 1 addition & 2 deletions client/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"strconv"

"github.com/maxmind/geoipupdate/v7/internal"
"github.com/maxmind/geoipupdate/v7/internal/vars"
)

Expand Down Expand Up @@ -51,7 +50,7 @@ func (c *Client) getMetadata(
}

if response.StatusCode != http.StatusOK {
httpErr := internal.HTTPError{
httpErr := HTTPError{
Body: string(responseBody),
StatusCode: response.StatusCode,
}
Expand Down

0 comments on commit 27c4b81

Please sign in to comment.