Skip to content

Commit

Permalink
fix: enhance Seencheck function
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Nov 28, 2024
1 parent 3229917 commit 03eb9e7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions seencheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 03eb9e7

Please sign in to comment.