From fb49ad24d5418ee9b7f65e9c36f07a1717608fcb Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 21 May 2018 12:24:48 -0700 Subject: Improve error handling in integration clients --- integration/instapaper/instapaper.go | 6 +++++- integration/nunuxkeeper/nunuxkeeper.go | 6 +++++- integration/pinboard/pinboard.go | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'integration') diff --git a/integration/instapaper/instapaper.go b/integration/instapaper/instapaper.go index ee44edd..3b9e91c 100644 --- a/integration/instapaper/instapaper.go +++ b/integration/instapaper/instapaper.go @@ -31,11 +31,15 @@ func (c *Client) AddURL(link, title string) error { clt := client.New(apiURL) clt.WithCredentials(c.username, c.password) response, err := clt.Get() + if err != nil { + return fmt.Errorf("instapaper: unable to send url: %v", err) + } + if response.HasServerFailure() { return fmt.Errorf("instapaper: unable to send url, status=%d", response.StatusCode) } - return err + return nil } // NewClient returns a new Instapaper client. diff --git a/integration/nunuxkeeper/nunuxkeeper.go b/integration/nunuxkeeper/nunuxkeeper.go index cb340ab..76367e1 100644 --- a/integration/nunuxkeeper/nunuxkeeper.go +++ b/integration/nunuxkeeper/nunuxkeeper.go @@ -47,11 +47,15 @@ func (c *Client) AddEntry(link, title, content string) error { clt := client.New(apiURL) clt.WithCredentials("api", c.apiKey) response, err := clt.PostJSON(doc) + if err != nil { + return fmt.Errorf("nunux-keeper: unable to send entry: %v", err) + } + if response.HasServerFailure() { return fmt.Errorf("nunux-keeper: unable to send entry, status=%d", response.StatusCode) } - return err + return nil } // NewClient returns a new Nunux Keeepr client. diff --git a/integration/pinboard/pinboard.go b/integration/pinboard/pinboard.go index d34e4fe..0de1dd2 100644 --- a/integration/pinboard/pinboard.go +++ b/integration/pinboard/pinboard.go @@ -36,11 +36,15 @@ func (c *Client) AddBookmark(link, title, tags string, markAsUnread bool) error clt := client.New("https://api.pinboard.in/v1/posts/add?" + values.Encode()) response, err := clt.Get() + if err != nil { + return fmt.Errorf("pinboard: unable to send bookmark: %v", err) + } + if response.HasServerFailure() { return fmt.Errorf("pinboard: unable to send bookmark, status=%d", response.StatusCode) } - return err + return nil } // NewClient returns a new Pinboard client. -- cgit v1.2.3