Wallabag integration: add more information in error message

This commit is contained in:
Frédéric Guillot 2023-07-10 19:40:56 -07:00
parent 92bb040640
commit 309e6d1084
1 changed files with 6 additions and 6 deletions

View File

@ -45,7 +45,7 @@ func (c *Client) AddEntry(link, title, content string) error {
func (c *Client) createEntry(accessToken, link, title, content string) error {
endpoint, err := url.JoinPath(c.baseURL, "/api/entries.json")
if err != nil {
return fmt.Errorf("wallbag: unable to get entries endpoint: %v", err)
return fmt.Errorf("wallbag: unable to generate entries endpoint using %q: %v", c.baseURL, err)
}
data := map[string]string{"url": link, "title": title}
@ -57,11 +57,11 @@ func (c *Client) createEntry(accessToken, link, title, content string) error {
clt.WithAuthorization("Bearer " + accessToken)
response, err := clt.PostJSON(data)
if err != nil {
return fmt.Errorf("wallabag: unable to post entry: %v", err)
return fmt.Errorf("wallabag: unable to post entry using %q endpoint: %v", endpoint, err)
}
if response.HasServerFailure() {
return fmt.Errorf("wallabag: request failed, status=%d", response.StatusCode)
return fmt.Errorf("wallabag: request failed using %q, status=%d", endpoint, response.StatusCode)
}
return nil
@ -77,17 +77,17 @@ func (c *Client) getAccessToken() (string, error) {
endpoint, err := url.JoinPath(c.baseURL, "/oauth/v2/token")
if err != nil {
return "", fmt.Errorf("wallbag: unable to get token endpoint: %v", err)
return "", fmt.Errorf("wallbag: unable to generate token endpoint using %q: %v", c.baseURL, err)
}
clt := client.New(endpoint)
response, err := clt.PostForm(values)
if err != nil {
return "", fmt.Errorf("wallabag: unable to get access token: %v", err)
return "", fmt.Errorf("wallabag: unable to get access token using %q endpoint: %v", endpoint, err)
}
if response.HasServerFailure() {
return "", fmt.Errorf("wallabag: request failed, status=%d", response.StatusCode)
return "", fmt.Errorf("wallabag: request failed using %q, status=%d", endpoint, response.StatusCode)
}
token, err := decodeTokenResponse(response.Body)