changes for error msg

This commit is contained in:
simonkellet 2022-09-03 13:46:41 +01:00
parent 7325d252c7
commit 6a6afcc232
4 changed files with 6 additions and 2 deletions

View File

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

View File

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

View File

@ -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)
}

3
web.go
View File

@ -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