Improve error handling and logging in HTTP request execution
All checks were successful
Golan Testing / testing (1.24.x, ubuntu-latest) (push) Successful in 26s

This commit is contained in:
2025-07-02 17:24:57 +03:00
parent 16af99d38e
commit d616854f4e

View File

@ -204,28 +204,44 @@ func (c *Client) IsAlive() bool {
func (c *Client) execute(method string, url string, params map[string]string, j bool) (*Response, error) {
// defer timeTrack("[TIMETRK] Executing HTTP Request")
var resp *resty.Response
var err error
// c.logger.Debug("executing http request", "method", method, "url", url, "params", params)
// GET Requests
if method == GET {
resp, _ = c.httpClient.
resp, err = c.httpClient.
R().
SetQueryParams(params).
Get(url)
if err != nil {
c.logger.Error("error while executing GET request", "request", "execute", "method", method, "url", url, "error", err.Error())
return nil, err
}
c.logger.Debug("executed GET request", "method", method, "url", url, "params", params)
}
// POST Requests
if method == POST {
if j { // POST > JSON Body
resp, _ = c.httpClient.
resp, err = c.httpClient.
R().
SetBody(params).
Post(url)
if err != nil {
c.logger.Error("error while executing POST request", "request", "execute", "method", method, "url", url, "error", err.Error())
return nil, err
}
} else { // POST > Form Data
resp, _ = c.httpClient.
resp, err = c.httpClient.
R().
SetFormData(params).
Post(url)
if err != nil {
c.logger.Error("error while executing POST request", "request", "execute", "method", method, "url", url, "error", err.Error())
return nil, err
}
}
c.logger.Debug("executed POST request", "method", method, "url", url, "params", params)
}
if resp.IsSuccess() {