Skip to content

Commit

Permalink
handle status code from api.mojang.com (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Engin Diri <[email protected]>
  • Loading branch information
Engin Diri authored Jul 11, 2021
1 parent 9dd1181 commit f35ee1c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exporter
import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -614,6 +615,10 @@ func (e *Exporter) getPlayerStats(ch chan<- prometheus.Metric) error {
level.Error(e.logger).Log("msg", "Failed to connect to api.mojang.com", "err", err)
}

if resp.StatusCode != 200 {
return fmt.Errorf("error retrieving player info from api.mojang.com: %w", errors.New(fmt.Sprintf("Status Code: %d", resp.StatusCode)))
}

var cResp []Player

if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil {
Expand Down

0 comments on commit f35ee1c

Please sign in to comment.