From 27c4b81836503de047269f902075cd15cd1aff7f Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Tue, 5 Nov 2024 11:17:28 -0500 Subject: [PATCH] Export HTTPError Lets callers use `errors.As` to differentiate transient outages from license problems. fixes #341 --- client/download.go | 10 +++++++++- client/metadata.go | 3 +-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/download.go b/client/download.go index f7d24cc..bc06972 100644 --- a/client/download.go +++ b/client/download.go @@ -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 @@ -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, @@ -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, } diff --git a/client/metadata.go b/client/metadata.go index d6119ee..e7e40e3 100644 --- a/client/metadata.go +++ b/client/metadata.go @@ -9,7 +9,6 @@ import ( "net/url" "strconv" - "github.com/maxmind/geoipupdate/v7/internal" "github.com/maxmind/geoipupdate/v7/internal/vars" ) @@ -51,7 +50,7 @@ func (c *Client) getMetadata( } if response.StatusCode != http.StatusOK { - httpErr := internal.HTTPError{ + httpErr := HTTPError{ Body: string(responseBody), StatusCode: response.StatusCode, }