diff --git a/post.go b/post.go index a027d2a..cc72da9 100644 --- a/post.go +++ b/post.go @@ -29,7 +29,7 @@ func (c *Client) do(ctx context.Context, form url.Values) ([]byte, error) { req.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, err := c.httpClient().Do(req) - if err != nil { + if (err != nil) || (resp == nil) { return nil, fmt.Errorf("failed to contact API: %w", err) } diff --git a/post_test.go b/post_test.go index 66d1b89..47a06aa 100644 --- a/post_test.go +++ b/post_test.go @@ -135,7 +135,7 @@ func TestUpdateOK(t *testing.T) { _, err := client.Update(ctx, records) if err != nil { var netErr net.Error - if errors.As(err, &netErr) && netErr.Timeout() { + if errors.As(err, &netErr) && (netErr != nil) && netErr.Timeout() { t.Errorf("Timeoutsss: %s", netErr) } else { t.Errorf("Successful post should return OK but failed with error: %s", err)