Skip to content

Commit

Permalink
Print error message received from RocketChat API
Browse files Browse the repository at this point in the history
  • Loading branch information
krakowski committed Oct 30, 2020
1 parent 40a25cb commit ee86e2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions api/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ type AttachmentField struct {
type MessageResponse struct {
Channel string `json:"channel"`
Success bool `json:"success"`
Error string `json:"error"`
}

type MessageError struct {
Success bool `json:"success"`
Error string `json:"error"`
ErrorType string `json:"errorType"`
}
8 changes: 6 additions & 2 deletions api/message_post.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package rocket

import "errors"
import (
"fmt"
)

const (
postMessagePath = "api/v1/chat.postMessage"
)

func (message *MessageService) Post(payload MessagePayload) (*MessageResponse, error) {

var msgError MessageError
var response MessageResponse
_, err := message.resty.R().
SetBody(payload).
SetError(&msgError).
SetResult(&response).
Post(postMessagePath)

if !response.Success {
return nil, errors.New("Posting message failed")
return nil, fmt.Errorf("Posting message to channel %s failed (%s)", payload.Channel, msgError.Error)
}

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.2"
version = "1.0.3"
)

var rootCommand = &cobra.Command{
Expand Down

0 comments on commit ee86e2c

Please sign in to comment.