Skip to content

Commit

Permalink
Print raw response on error
Browse files Browse the repository at this point in the history
  • Loading branch information
krakowski committed Oct 30, 2020
1 parent ee86e2c commit 3180969
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion api/auth_login.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package rocket

import (
"fmt"
"net/http"
)

const (
loginPath string = "api/v1/login"
)

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)

Expand Down
4 changes: 2 additions & 2 deletions api/message_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

const (
version = "1.0.3"
version = "1.0.4"
)

var rootCommand = &cobra.Command{
Expand Down

0 comments on commit 3180969

Please sign in to comment.