summaryrefslogtreecommitdiff
path: root/scrape.go
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2024-02-17 21:47:43 +0100
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2024-02-17 21:47:43 +0100
commit0b4c723d2c310310efba41f58ee3a626510bcd3a (patch)
tree65017d8bdc18236557c466d0b51dc9983a891902 /scrape.go
parentf2d36972b238cb6bfe2548ec59508bbd83be0a05 (diff)
Mark non 2XX status code as errors
Diffstat (limited to 'scrape.go')
-rw-r--r--scrape.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/scrape.go b/scrape.go
index 3e38e46..bf0e1d6 100644
--- a/scrape.go
+++ b/scrape.go
@@ -9,6 +9,7 @@ import (
"log"
"net/http"
"net/http/cookiejar"
+ "strconv"
"sync"
"github.com/cornelk/hashmap"
@@ -187,6 +188,10 @@ func (s *Scraper) process(url string, depth int) {
response.StatusCode = resp.StatusCode
response.Headers = resp.Header
+ if response.StatusCode < 200 || response.StatusCode >= 300 {
+ response.Error = strconv.Itoa(response.StatusCode) + " " + http.StatusText(response.StatusCode)
+ }
+
response.Body, err = io.ReadAll(resp.Body)
if err != nil {
response.Error = err