Skip to content

Commit

Permalink
proper error handling of 401 unauthorized. bumped version to 0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ogazitt committed Jun 11, 2020
1 parent ed2c3c2 commit 9a16774
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ func call(path string, verb string, payload interface{ io.Reader }) ([]byte, err
os.Exit(1)
}

// check for Unauthorized
if res.StatusCode == 401 {
fmt.Println("snap: token expired; please log in again")
os.Exit(1)
}

// process the response
defer res.Body.Close()
contents, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Printf("snap: error reading HTTP response from HTTP request against %s\nerror: %s\n", url, err)
fmt.Printf("snap: error reading HTTP response from HTTP request for %s\nerror: %s\n", url, err)
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package version

// Version number
var Version string = "0.5.3"
var Version string = "0.5.4"

// GitHash of the last commit
var GitHash string

0 comments on commit 9a16774

Please sign in to comment.