From 6d068b5269a1ed4fe8d9bcf67d01758b1876ecbc Mon Sep 17 00:00:00 2001 From: TeoGoddet <9885447+TeoGoddet@users.noreply.github.com> Date: Thu, 28 Jan 2021 00:45:52 +0100 Subject: [PATCH] infomaniak: Make error message more meaningful (#1332) --- providers/dns/infomaniak/internal/client.go | 2 +- providers/dns/infomaniak/internal/models.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/providers/dns/infomaniak/internal/client.go b/providers/dns/infomaniak/internal/client.go index 19d2e81f..5f197624 100644 --- a/providers/dns/infomaniak/internal/client.go +++ b/providers/dns/infomaniak/internal/client.go @@ -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 diff --git a/providers/dns/infomaniak/internal/models.go b/providers/dns/infomaniak/internal/models.go index 434fa913..7056354d 100644 --- a/providers/dns/infomaniak/internal/models.go +++ b/providers/dns/infomaniak/internal/models.go @@ -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) +}