From 33c02a98f26bfe401a3060e1f225f789f93277b9 Mon Sep 17 00:00:00 2001 From: Azamat <25627421+mazamats@users.noreply.github.com> Date: Thu, 14 Nov 2019 13:22:12 -0700 Subject: [PATCH] return error if credentials are invalid --- client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 8ebac12..01562c3 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package rabbithole import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" "net/url" @@ -108,7 +109,13 @@ func executeRequest(client *Client, req *http.Request) (res *http.Response, err if client.transport != nil { httpc.Transport = client.transport } - return httpc.Do(req) + resp, err := httpc.Do(req) + + if resp.StatusCode == 401 { + return nil, errors.New("Error: HTTP 401 Unauthorized, check username or password") + } + + return resp, err } func executeAndParseRequest(client *Client, req *http.Request, rec interface{}) (err error) {