summaryrefslogtreecommitdiff
path: root/pkg/vpn
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-09-08 19:24:25 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-09-08 19:24:25 +0200
commitcda7f02569e1ad214eb0755527038784cfd54467 (patch)
tree026b2a9d1ccace5af684483d6456978424a505c2 /pkg/vpn
parent2f1f352342e8e707beabd8d0c180887182e28c9a (diff)
[refactor] fix error handling after review
Diffstat (limited to 'pkg/vpn')
-rw-r--r--pkg/vpn/bonafide/auth_sip.go8
-rw-r--r--pkg/vpn/bonafide/bonafide.go8
2 files changed, 9 insertions, 7 deletions
diff --git a/pkg/vpn/bonafide/auth_sip.go b/pkg/vpn/bonafide/auth_sip.go
index 0c8ee4f..5da562d 100644
--- a/pkg/vpn/bonafide/auth_sip.go
+++ b/pkg/vpn/bonafide/auth_sip.go
@@ -70,25 +70,27 @@ func writeToken(token []byte) {
tp := getTokenPath()
err := ioutil.WriteFile(tp, token, 0600)
if err != nil {
- log.Println("BUG: cannot write token to", tp)
+ log.Println("BUG: cannot write token to", tp, err)
}
}
func readToken() ([]byte, error) {
f, err := os.Open(getTokenPath())
if err != nil {
- log.Println("Error: cannot open token file")
+ log.Println("Error: cannot open token file", err)
return nil, err
}
token, err := ioutil.ReadAll(f)
if err != nil {
- log.Println("Error: cannot read token")
+ log.Println("Error: cannot read token", err)
return nil, err
}
return token, nil
}
func hasRecentToken() bool {
+ /* See https://0xacab.org/leap/bitmask-vpn/-/issues/346 for ability to refresh tokens,
+ when implemented that should be tried in a goroutine */
statinfo, err := os.Stat(getTokenPath())
if err != nil {
return false
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index 9916b55..6630352 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -239,7 +239,7 @@ func (b *Bonafide) fetchGeolocation() ([]string, error) {
client := &http.Client{}
_resp, err := client.Post(config.GeolocationAPI, "", nil)
if err != nil {
- log.Println("ERROR: could not fetch geolocation:", fmt.Errorf("%s", err))
+ log.Printf("ERROR: could not fetch geolocation: %s\n", err)
return nil, err
}
resp = _resp
@@ -247,15 +247,15 @@ func (b *Bonafide) fetchGeolocation() ([]string, error) {
defer resp.Body.Close()
if resp.StatusCode != 200 {
- 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)
+ log.Println("ERROR: bad status code while fetching geolocation:", resp.StatusCode)
+ return nil, fmt.Errorf("Get geolocation failed with status: %s", resp.StatusCode)
}
geo := &geoLocation{}
dataJSON, err := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(dataJSON, &geo)
if err != nil {
- log.Println("ERROR: cannot parse geolocation json", fmt.Errorf("%s", err))
+ log.Printf("ERROR: cannot parse geolocation json: %s\n", err)
log.Println(string(dataJSON))
_ = fmt.Errorf("bad json")
return nil, err