From 03eb9e78fdbcda81b05c99421a15e5d42c43240f Mon Sep 17 00:00:00 2001 From: Corentin Barreau Date: Thu, 28 Nov 2024 21:05:51 +0100 Subject: [PATCH] fix: enhance Seencheck function --- seencheck.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/seencheck.go b/seencheck.go index c62bc1a..79f6971 100644 --- a/seencheck.go +++ b/seencheck.go @@ -3,12 +3,11 @@ package gocrawlhq import ( "bytes" "encoding/json" + "errors" "net/http" ) func (c *Client) Seencheck(URLs []URL) (outputURLs []URL, err error) { - expectedStatusCodes := []int{200, 204} - jsonPayload, err := json.Marshal(URLs) if err != nil { return URLs, err @@ -33,15 +32,13 @@ func (c *Client) Seencheck(URLs []URL) (outputURLs []URL, err error) { } defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&outputURLs) - if err != nil { - return URLs, err - } - - for _, expectedStatusCode := range expectedStatusCodes { - if resp.StatusCode == expectedStatusCode { - return outputURLs, nil + if resp.StatusCode == 200 { + err = json.NewDecoder(resp.Body).Decode(&outputURLs) + if err != nil { + return URLs, err } + } else if resp.StatusCode != 200 { + return URLs, errors.New("unexpected status code: " + resp.Status) } return outputURLs, err