From 318096918011567232162b80809ee8cecab67262 Mon Sep 17 00:00:00 2001 From: Filip Krakowski Date: Fri, 30 Oct 2020 17:11:16 +0100 Subject: [PATCH] Print raw response on error --- api/auth_login.go | 12 +++++++++++- api/message_post.go | 4 ++-- cmd/root.go | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/api/auth_login.go b/api/auth_login.go index 5bc7f46..c0271a0 100644 --- a/api/auth_login.go +++ b/api/auth_login.go @@ -1,5 +1,10 @@ package rocket +import ( + "fmt" + "net/http" +) + const ( loginPath string = "api/v1/login" ) @@ -7,15 +12,20 @@ const ( func (auth *AuthService) Login(username string, password string) error { var response AuthResponse - _, err := auth.resty.R(). + resp, err := auth.resty.R(). SetBody(AuthRequest{Username: username, Password: password}). SetResult(&response). + SetError(&LastError). Post(loginPath) if err != nil { return err } + if resp.StatusCode() != http.StatusOK { + return fmt.Errorf("Authentication failed : %s", resp) + } + auth.resty.SetHeader("X-Auth-Token", response.Data.AuthToken) auth.resty.SetHeader("X-User-Id", response.Data.UserId) diff --git a/api/message_post.go b/api/message_post.go index 9e61e1b..20eee11 100644 --- a/api/message_post.go +++ b/api/message_post.go @@ -12,14 +12,14 @@ func (message *MessageService) Post(payload MessagePayload) (*MessageResponse, e var msgError MessageError var response MessageResponse - _, err := message.resty.R(). + resp, err := message.resty.R(). SetBody(payload). SetError(&msgError). SetResult(&response). Post(postMessagePath) if !response.Success { - return nil, fmt.Errorf("Posting message to channel %s failed (%s)", payload.Channel, msgError.Error) + return nil, fmt.Errorf("Posting message to channel %s failed : %s", payload.Channel, resp) } return &response, err diff --git a/cmd/root.go b/cmd/root.go index de27cdf..1ed13e7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,7 @@ import ( ) const ( - version = "1.0.3" + version = "1.0.4" ) var rootCommand = &cobra.Command{