diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-08-19 17:40:36 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-08-20 20:27:47 +0200 |
commit | 709220836e10f559a11c2b70177f6d58d9b7a0a1 (patch) | |
tree | 17edf8c6d0d20e133f5dcb2747ea4dc35533a4ea /pkg/vpn/bonafide/bonafide.go | |
parent | b9cae0b715ce34cfb0b7f85f023c31ef8ddd54d3 (diff) |
[debug] improve error handling for geolocation
Diffstat (limited to 'pkg/vpn/bonafide/bonafide.go')
-rw-r--r-- | pkg/vpn/bonafide/bonafide.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index b81fd84..9963448 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -232,23 +232,36 @@ func (b *Bonafide) GetOpenvpnArgs() ([]string, error) { } func (b *Bonafide) fetchGeolocation() ([]string, error) { + /* FIXME in float deployments, geolocation is served on gemyip.domain/json, with a LE certificate. + So this is a workaround until we streamline that behavior */ resp, err := b.client.Post(config.GeolocationAPI, "", nil) if err != nil { - return nil, err + client := &http.Client{} + _resp, err := client.Post(config.GeolocationAPI, "", nil) + if err != nil { + log.Println("ERROR: could not fetch geolocation:", fmt.Errorf("%s", err)) + return nil, err + } + resp = _resp } + defer resp.Body.Close() if resp.StatusCode != 200 { - return nil, fmt.Errorf("get geolocation failed with status: %s", resp.Status) + log.Println("ERROR: bad status code while fetching geolocation:", fmt.Errorf("%s", resp.Status)) + return nil, fmt.Errorf("Get geolocation failed with status: %s", resp.Status) } geo := &geoLocation{} dataJSON, err := ioutil.ReadAll(resp.Body) err = json.Unmarshal(dataJSON, &geo) if err != nil { - _ = fmt.Errorf("get vpn cert has failed with status: %s", resp.Status) + log.Println("ERROR: cannot parse geolocation json", fmt.Errorf("%s", err)) + log.Println(string(dataJSON)) + _ = fmt.Errorf("bad json") return nil, err } + log.Println("Got sorted gateways:", geo.SortedGateways) return geo.SortedGateways, nil } |