In case of non 200 response return error

This commit is contained in:
Asim Aslam 2019-09-25 16:53:06 +01:00
parent 140e3d576c
commit dfcedbab1e

View File

@ -3,6 +3,7 @@ package http
import ( import (
"encoding/json" "encoding/json"
"errors"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
@ -58,7 +59,9 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
return nil, err return nil, err
} }
defer rsp.Body.Close() defer rsp.Body.Close()
if rsp.StatusCode != 200 {
return nil, errors.New("non 200 response")
}
b, err := ioutil.ReadAll(rsp.Body) b, err := ioutil.ReadAll(rsp.Body)
if err != nil { if err != nil {
return nil, err return nil, err