Improve error handling in integration clients
This commit is contained in:
parent
b270159aae
commit
fb49ad24d5
3 changed files with 15 additions and 3 deletions
|
@ -31,11 +31,15 @@ func (c *Client) AddURL(link, title string) error {
|
||||||
clt := client.New(apiURL)
|
clt := client.New(apiURL)
|
||||||
clt.WithCredentials(c.username, c.password)
|
clt.WithCredentials(c.username, c.password)
|
||||||
response, err := clt.Get()
|
response, err := clt.Get()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("instapaper: unable to send url: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if response.HasServerFailure() {
|
if response.HasServerFailure() {
|
||||||
return fmt.Errorf("instapaper: unable to send url, status=%d", response.StatusCode)
|
return fmt.Errorf("instapaper: unable to send url, status=%d", response.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Instapaper client.
|
// NewClient returns a new Instapaper client.
|
||||||
|
|
|
@ -47,11 +47,15 @@ func (c *Client) AddEntry(link, title, content string) error {
|
||||||
clt := client.New(apiURL)
|
clt := client.New(apiURL)
|
||||||
clt.WithCredentials("api", c.apiKey)
|
clt.WithCredentials("api", c.apiKey)
|
||||||
response, err := clt.PostJSON(doc)
|
response, err := clt.PostJSON(doc)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("nunux-keeper: unable to send entry: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if response.HasServerFailure() {
|
if response.HasServerFailure() {
|
||||||
return fmt.Errorf("nunux-keeper: unable to send entry, status=%d", response.StatusCode)
|
return fmt.Errorf("nunux-keeper: unable to send entry, status=%d", response.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Nunux Keeepr client.
|
// NewClient returns a new Nunux Keeepr client.
|
||||||
|
|
|
@ -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())
|
clt := client.New("https://api.pinboard.in/v1/posts/add?" + values.Encode())
|
||||||
response, err := clt.Get()
|
response, err := clt.Get()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("pinboard: unable to send bookmark: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if response.HasServerFailure() {
|
if response.HasServerFailure() {
|
||||||
return fmt.Errorf("pinboard: unable to send bookmark, status=%d", response.StatusCode)
|
return fmt.Errorf("pinboard: unable to send bookmark, status=%d", response.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Pinboard client.
|
// NewClient returns a new Pinboard client.
|
||||||
|
|
Loading…
Reference in a new issue