infomaniak: Make error message more meaningful (#1332)

This commit is contained in:
TeoGoddet 2021-01-28 00:45:52 +01:00 committed by GitHub
parent 16660b23e4
commit 6d068b5269
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -153,7 +153,7 @@ func (c *Client) do(req *http.Request) (*APIResponse, error) {
}
if resp.Result != "success" {
return nil, fmt.Errorf("unexpected API result (%s): %v", resp.Result, resp.ErrResponse)
return nil, fmt.Errorf("%d: unexpected API result (%s): %w", rawResp.StatusCode, resp.Result, resp.ErrResponse)
}
return &resp, nil

View file

@ -1,6 +1,9 @@
package internal
import "encoding/json"
import (
"encoding/json"
"fmt"
)
// Record a DNS record.
type Record struct {
@ -28,3 +31,7 @@ type APIErrorResponse struct {
Context map[string]string `json:"context,omitempty"`
Errors []APIErrorResponse `json:"errors,omitempty"`
}
func (a APIErrorResponse) Error() string {
return fmt.Sprintf("code: %s, description: %s", a.Code, a.Description)
}