Skip to content

Commit

Permalink
fix new town error return
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasehlert committed Jul 5, 2024
1 parent 6c80e1d commit 528c8a3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"net/url"
"runtime"
"strings"
"time"

Expand All @@ -19,16 +20,21 @@ import (
)

func getDoc(client *resty.Client, endpoint string) (*goquery.Document, error) {
// Get the details of the calling function
pc, _, _, _ := runtime.Caller(1)
callingFunc := strings.Split(runtime.FuncForPC(pc).Name(), ".")[2]

// Get the document from the endpoint
res, err := client.R().Get(endpoint)
if err != nil {
return nil, fmt.Errorf("issue getting doc for %s endpoint. Error: %s", endpoint, err)
}

switch res.StatusCode() {
case http.StatusOK:
log.Println("[info] Retrieving data successfully from tibia.com.")
log.Printf("[info] Retrieving data successfully for %s from tibia.com.", callingFunc)
default:
return nil, fmt.Errorf("issue when collecting data from tibia.com. StatusCode: %d", res.StatusCode())
return nil, fmt.Errorf("issue when collecting data for %s from tibia.com. StatusCode: %d", callingFunc, res.StatusCode())
}

// Convert body to io.Reader
Expand Down Expand Up @@ -105,7 +111,7 @@ func (b *Builder) housesWorker(client *resty.Client) error {
})
}
default:
return fmt.Errorf("issue when collecting data from %s. StatusCode: %d", TibiaDataAPIhost, res.StatusCode())
log.Printf("[warn] Issue when retrieving data about houses and guildhalls in %s. StatusCode: %d", town, res.StatusCode())
}

if sleepFlag {
Expand Down

0 comments on commit 528c8a3

Please sign in to comment.