Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mandrill.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ func (c *Client) sendApiRequest(data interface{}, path string) (body []byte, err

if resp.StatusCode >= 400 {
resError := &Error{}
err = json.Unmarshal(body, resError)
if err = json.Unmarshal(body, resError); err != nil {
return body, err
}

return body, resError
}

Expand Down
13 changes: 13 additions & 0 deletions mandrill_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mandrill

import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -82,6 +83,18 @@ func Test_MessagesSendTemplate_Fail(t *testing.T) {
expect(t, reflect.DeepEqual(correctResponse, err), true)
}

func Test_MessagesSendTemplate_Fail_Invalid_JSON(t *testing.T) {
server, m := testTools(400, ``)
defer server.Close()
responses, err := m.MessagesSendTemplate(&Message{}, "cheese", map[string]string{"name": "bob"})

expect(t, len(responses), 0)

correctResponse := json.Unmarshal([]byte(` `), struct{}{})
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json.SyntaxError has only Offset field exported, so this is the easiest way to test this case in current testing flow.


expect(t, reflect.DeepEqual(correctResponse, err), true)
}

// MessagesSend //////////

func Test_MessageSend_Success(t *testing.T) {
Expand Down