changes for error msg
This commit is contained in:
parent
7325d252c7
commit
6a6afcc232
1
json.go
1
json.go
@ -16,4 +16,5 @@ func loadJSON(file string) (WeatherAPI, error) {
|
||||
jsonParser := json.NewDecoder(configFile)
|
||||
jsonParser.Decode(&config)
|
||||
return config, err
|
||||
|
||||
}
|
||||
|
3
main.go
3
main.go
@ -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
3
web.go
@ -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…
x
Reference in New Issue
Block a user