Enhance authentication error handling and logging in auth function
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 25s
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 25s
This commit is contained in:
14
client.go
14
client.go
@ -51,10 +51,14 @@ func New(config *config.Config) (*Client, error) {
|
|||||||
"Accept": "*/*"})
|
"Accept": "*/*"})
|
||||||
|
|
||||||
client.httpClient = httpClient
|
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
|
var sd SessionData
|
||||||
err := json.Unmarshal(resp.Data, &sd)
|
err = json.Unmarshal(resp.Data, &sd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.logger.Error("error while parsing json", "request", "auth", "error", err.Error())
|
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 .
|
// auth .
|
||||||
func (c *Client) auth() *Response {
|
func (c *Client) auth() (*Response, error) {
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
"env": "cloudprod",
|
"env": "cloudprod",
|
||||||
"deviceType": "android",
|
"deviceType": "android",
|
||||||
@ -290,10 +294,10 @@ func (c *Client) auth() *Response {
|
|||||||
c.logger.Debug("AUTH HTTP OUTPUT", "body", resp)
|
c.logger.Debug("AUTH HTTP OUTPUT", "body", resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error("error while executing auth request", "request", "auth", "error", err.Error())
|
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)
|
c.logger.Debug("AUTH HTTP OUTPUT", "body", resp)
|
||||||
return resp
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseResponse .
|
// parseResponse .
|
||||||
|
Reference in New Issue
Block a user