From 3e02c6f2d54205606441355f8da4c2cdae54d822 Mon Sep 17 00:00:00 2001 From: jeezft Date: Fri, 16 Jan 2026 02:19:24 +0300 Subject: [PATCH] improved error messages --- api/fiscal.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/api/fiscal.go b/api/fiscal.go index 7eadc8a..34c920b 100644 --- a/api/fiscal.go +++ b/api/fiscal.go @@ -18,6 +18,7 @@ func (c *Client) executeRequest(ctx context.Context, request FiscalRequest, resp resp, err := c.resty.R(). SetContext(ctx). SetHeader("Authorization", c.token). + SetHeader("Content-Type", "application/json"). SetBody(reqJson). Post(c.apiBaseURL + c.fiscalEndpoint) @@ -25,21 +26,17 @@ func (c *Client) executeRequest(ctx context.Context, request FiscalRequest, resp return fmt.Errorf("request failed: %w", err) } - if resp.IsError() { - return fmt.Errorf("api error: %v", resp.Error()) - } - - if resp.StatusCode() != 200 { - return fmt.Errorf("unexpected status code: %d", resp.StatusCode()) - } - body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("failed to read response: %w", err) } + if resp.StatusCode() != 200 { + return fmt.Errorf("api error (status %d): %s", resp.StatusCode(), string(body)) + } + if err := json.Unmarshal(body, response); err != nil { - return fmt.Errorf("failed to unmarshal response: %w", err) + return fmt.Errorf("failed to unmarshal response: %w, body: %s", err, string(body)) } return nil