changes for error msg

master
simonkellet 2 years ago
parent 7325d252c7
commit 6a6afcc232
  1. 1
      file.go
  2. 1
      json.go
  3. 3
      main.go
  4. 3
      web.go

@ -23,4 +23,5 @@ func removeFile(file string) {
if e != nil {
log.Fatal(e)
}
}

@ -16,4 +16,5 @@ func loadJSON(file string) (WeatherAPI, error) {
jsonParser := json.NewDecoder(configFile)
jsonParser.Decode(&config)
return config, err
}

@ -19,7 +19,8 @@ func main() {
//read webpage
html, err := loadWebPage(full)
if err != nil {
fmt.Println("4xx error, please try again!")
//fmt.Println("4xx error, please try again!")
fmt.Fprintf(os.Stderr, "ERROR: Could not read website: %s\n", err)
os.Exit(1)
}

@ -10,10 +10,11 @@ func loadWebPage(webURL string) ([]byte, error) {
resp, err := http.Get(webURL)
//reads html as a slice of bytes
html, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
//check response codes
if resp.StatusCode >= 400 && resp.StatusCode <= 499 {
err = fmt.Errorf("response Code: %v", resp.StatusCode)
err = fmt.Errorf("got response code %v", resp.StatusCode)
}
return html, err

Loading…
Cancel
Save