From b2a76f83cc23c1f98130bbb8a3c9de76fdf81713 Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Wed, 2 Jul 2025 17:28:07 +0300 Subject: [PATCH] Enhance authentication error handling and logging in auth function --- client.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 48e1a8e..5f82834 100644 --- a/client.go +++ b/client.go @@ -51,10 +51,14 @@ func New(config *config.Config) (*Client, error) { "Accept": "*/*"}) client.httpClient = httpClient - resp := client.auth() + resp, err := client.auth() + if err != nil { + client.logger.Error("error while executing auth request", "request", "auth", "error", err.Error()) + return nil, errors.New("error while executing auth request: " + err.Error()) + } var sd SessionData - err := json.Unmarshal(resp.Data, &sd) + err = json.Unmarshal(resp.Data, &sd) if err != nil { client.logger.Error("error while parsing json", "request", "auth", "error", err.Error()) } @@ -275,7 +279,7 @@ func (c *Client) execute(method string, url string, params map[string]string, j } // auth . -func (c *Client) auth() *Response { +func (c *Client) auth() (*Response, error) { params := map[string]string{ "env": "cloudprod", "deviceType": "android", @@ -290,10 +294,10 @@ func (c *Client) auth() *Response { c.logger.Debug("AUTH HTTP OUTPUT", "body", resp) if err != nil { c.logger.Error("error while executing auth request", "request", "auth", "error", err.Error()) - return nil + return nil, errors.New("error while executing auth request: " + err.Error()) } c.logger.Debug("AUTH HTTP OUTPUT", "body", resp) - return resp + return resp, nil } // parseResponse .